From 23e312eb3e00952345ac8d26ae72c2d500e7031d Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Wed, 28 Mar 2018 11:28:46 +0100 Subject: [PATCH 01/11] Add client/ directory --- postgres/{client.sls => client/init.sls} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename postgres/{client.sls => client/init.sls} (100%) diff --git a/postgres/client.sls b/postgres/client/init.sls similarity index 100% rename from postgres/client.sls rename to postgres/client/init.sls From feb2b386cede1f1847e6c8f15db40ae0fb6ee111 Mon Sep 17 00:00:00 2001 From: Brian Glogower Date: Sat, 31 Mar 2018 13:03:14 -0700 Subject: [PATCH 02/11] Allow setting dir mode for conf_dir in pillar The current mode of 0775 causes start problems: `FATAL: data directory "/var/lib/postgresql/9.6/main" has group or world access` --- postgres/defaults.yaml | 1 + postgres/server/init.sls | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index aff9607..e737366 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -21,6 +21,7 @@ postgres: env: [] conf_dir: /var/lib/pgsql/data + conf_dir_mode: 0775 postgresconf: "" macos: diff --git a/postgres/server/init.sls b/postgres/server/init.sls index 6e2b23b..daf9d1b 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -72,7 +72,7 @@ postgresql-config-dir: - name: {{ postgres.conf_dir }} - user: {{ postgres.user }} - group: {{ postgres.group }} - - dir_mode: 775 + - dir_mode: {{ postgres.conf_dir_mode }} - force: True - file_mode: 644 - recurse: From cc30fbb9032c857583e3cca4ff65bb02288220ef Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Sat, 31 Mar 2018 21:56:58 +0100 Subject: [PATCH 03/11] Updated alternatives solution --- postgres/client.sls | 3 ++- postgres/dev.sls | 17 +++++++++++++++-- postgres/osfamilymap.yaml | 4 ++++ postgres/server/init.sls | 3 ++- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/postgres/client.sls b/postgres/client.sls index 473f3c6..d315ea1 100644 --- a/postgres/client.sls +++ b/postgres/client.sls @@ -27,8 +27,9 @@ postgresql-client-libs: {%- for bin in postgres.client_bins %} {%- set path = salt['file.join'](postgres.bin_dir, bin) %} -{{ bin }}: +postgresql-{{ bin }}-altinstall: alternatives.install: + - name: {{ bin }} - link: {{ salt['file.join']('/usr/bin', bin) }} - path: {{ path }} - priority: {{ postgres.linux.altpriority }} diff --git a/postgres/dev.sls b/postgres/dev.sls index c9f330b..24e7704 100644 --- a/postgres/dev.sls +++ b/postgres/dev.sls @@ -14,10 +14,23 @@ install-postgres-libpq-dev: - name: {{ postgres.pkg_libpq_dev }} {% endif %} -{% endif %} +# Alternatives system. Make devclient binaries available in $PATH + {%- if 'bin_dir' in postgres and postgres.linux.altpriority %} + {%- for bin in postgres.dev_bins %} + {%- set path = salt['file.join'](postgres.bin_dir, bin) %} +postgresql-{{ bin }}-altinstall: + alternatives.install: + - name: {{ bin }} + - link: {{ salt['file.join']('/usr/bin', bin) }} + - path: {{ path }} + - priority: {{ postgres.linux.altpriority }} + - onlyif: test -f {{ path }} -{% if grains.os == 'MacOS' %} + {%- endfor %} + {%- endif %} + +{% elif grains.os == 'MacOS' %} # Darwin maxfiles limits {% if postgres.limits.soft or postgres.limits.hard %} diff --git a/postgres/osfamilymap.yaml b/postgres/osfamilymap.yaml index 6d241ac..786b834 100644 --- a/postgres/osfamilymap.yaml +++ b/postgres/osfamilymap.yaml @@ -56,6 +56,8 @@ RedHat: # directory containing PostgreSQL client executables bin_dir: /usr/pgsql-{{ repo.version }}/bin + dev_bins: + - ecg client_bins: - clusterdb - createdb @@ -129,6 +131,8 @@ Suse: # directory containing PostgreSQL client executables bin_dir: /usr/pgsql-{{ repo.version }}/bin + dev_bins: + - ecg client_bins: - pg_archivecleanup - pg_config diff --git a/postgres/server/init.sls b/postgres/server/init.sls index 6e2b23b..c643e25 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -40,8 +40,9 @@ postgresql-server: {%- for bin in postgres.server_bins %} {%- set path = salt['file.join'](postgres.bin_dir, bin) %} -{{ bin }}: +postgresql-{{ bin }}-altinstall: alternatives.install: + - name: {{ bin }} - link: {{ salt['file.join']('/usr/bin', bin) }} - path: {{ path }} - priority: {{ postgres.linux.altpriority }} From a4e184b79cebf8018803d657c622939654f76653 Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Mon, 9 Apr 2018 14:59:49 +0100 Subject: [PATCH 04/11] fromrepo support --- postgres/codenamemap.yaml | 9 ++++++++- postgres/defaults.yaml | 4 ++++ postgres/dev.sls | 6 ++++++ postgres/osfamilymap.yaml | 2 ++ postgres/python.sls | 3 +++ postgres/repo.yaml | 7 +++---- postgres/server/init.sls | 3 +++ 7 files changed, 29 insertions(+), 5 deletions(-) diff --git a/postgres/codenamemap.yaml b/postgres/codenamemap.yaml index 0b049e2..6946ff2 100644 --- a/postgres/codenamemap.yaml +++ b/postgres/codenamemap.yaml @@ -18,12 +18,18 @@ {# use upstream version if configured #} {% if repo.use_upstream_repo == true %} {% set version = repo.version %} + {% set fromrepo = repo.fromrepo or name + '-pgdg' %} + {% set pkg_dev = '' %} + {% else %} + {% set fromrepo = name %} + {% set pkg_dev = 'postgresql-server-dev-all' %} {% endif %} {{ codename|default(name, true) }}: # PostgreSQL packages are mostly downloaded from `main` repo component + fromrepo: {{ fromrepo }} pkg_repo: - name: 'deb http://apt.postgresql.org/pub/repos/apt {{ name }}-pgdg main {{ repo.version }}' + name: 'deb http://apt.postgresql.org/pub/repos/apt {{ name }}-pgdg main {{ version }}' pkg: postgresql-{{ version }} pkg_client: postgresql-client-{{ version }} conf_dir: /etc/postgresql/{{ version }}/main @@ -55,6 +61,7 @@ {{ codename|default(name, true) }}: # PostgreSQL packages are mostly downloaded from `main` repo component + fromrepo: {{ name }} pkg_repo: baseurl: 'https://download.postgresql.org/pub/repos/yum/{{ version }}/fedora/fedora-$releasever-$basearch' diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index e737366..f35cbc0 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -57,6 +57,10 @@ postgres: bake_image: False + fromrepo: + pkg_repo: + name: [] + users: {} tablespaces: {} databases: {} diff --git a/postgres/dev.sls b/postgres/dev.sls index c9f330b..c757ad5 100644 --- a/postgres/dev.sls +++ b/postgres/dev.sls @@ -6,12 +6,18 @@ install-postgres-dev-package: pkg.installed: - name: {{ postgres.pkg_dev }} + {% if postgres.fromrepo %} + - fromrepo: {{ postgres.fromrepo }} + {% endif %} {% endif %} {% if postgres.pkg_libpq_dev %} install-postgres-libpq-dev: pkg.installed: - name: {{ postgres.pkg_libpq_dev }} + {% if postgres.fromrepo %} + - fromrepo: {{ postgres.fromrepo }} + {% endif %} {% endif %} {% endif %} diff --git a/postgres/osfamilymap.yaml b/postgres/osfamilymap.yaml index 6d241ac..dbb3a28 100644 --- a/postgres/osfamilymap.yaml +++ b/postgres/osfamilymap.yaml @@ -39,6 +39,7 @@ RedHat: {% if repo.use_upstream_repo == true %} {% set data_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %} + fromrepo: pgdg{{ release }} pkg: postgresql{{ release }}-server pkg_client: postgresql{{ release }} pkg_libs: postgresql{{ release }}-libs @@ -112,6 +113,7 @@ Suse: {% if repo.use_upstream_repo == true %} {% set lib_dir = '/var/lib/pgsql/' ~ repo.version ~ '/data' %} + fromrepo: pgdg-sles-{{ release }} pkg: postgresql{{ release }}-server pkg_client: postgresql{{ release }} pkg_dev: postgresql{{ release }}-devel diff --git a/postgres/python.sls b/postgres/python.sls index a206bfc..171062c 100644 --- a/postgres/python.sls +++ b/postgres/python.sls @@ -3,3 +3,6 @@ postgresql-python: pkg.installed: - name: {{ postgres.pkg_python}} + {% if postgres.fromrepo %} + - fromrepo: {{ postgres.fromrepo }} + {% endif %} diff --git a/postgres/repo.yaml b/postgres/repo.yaml index 1d87463..46b1fa9 100644 --- a/postgres/repo.yaml +++ b/postgres/repo.yaml @@ -3,10 +3,9 @@ {% import_yaml "postgres/defaults.yaml" as defaults %} -use_upstream_repo: {{ salt['pillar.get']('postgres:use_upstream_repo', - defaults.postgres.use_upstream_repo) }} -version: {{ salt['pillar.get']('postgres:version', - defaults.postgres.version) }} +use_upstream_repo: {{ salt['pillar.get']('postgres:use_upstream_repo', defaults.postgres.use_upstream_repo) }} +version: {{ salt['pillar.get']('postgres:version', defaults.postgres.version) }} +fromrepo: {{ salt['pillar.get']('postgres:fromrepo', defaults.postgres.fromrepo) }} #Early lookup for system user on MacOS {% if grains.os == 'MacOS' %} diff --git a/postgres/server/init.sls b/postgres/server/init.sls index daf9d1b..1789425 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -23,6 +23,9 @@ postgresql-server: - require: - pkgrepo: postgresql-repo {%- endif %} + {%- if postgres.fromrepo %} + - fromrepo: {{ postgres.fromrepo }} + {%- endif %} {%- if grains.os == 'MacOS' %} #Register as Launchd LaunchAgent for system users - require_in: From 9b289b84026b9b042b947d0dd9b7a1d82e84ced2 Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Mon, 9 Apr 2018 15:50:17 +0100 Subject: [PATCH 05/11] Convert hex to decimal --- postgres/defaults.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index e737366..2e17dd8 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -21,7 +21,7 @@ postgres: env: [] conf_dir: /var/lib/pgsql/data - conf_dir_mode: 0775 + conf_dir_mode: '0775' postgresconf: "" macos: From 15f3d5f5b46a5a495787862d095b186b66563d18 Mon Sep 17 00:00:00 2001 From: Denys Havrysh Date: Wed, 11 Apr 2018 16:43:11 +0300 Subject: [PATCH 06/11] Fix compatibility with Salt 2018.3.0 --- postgres/server/init.sls | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/postgres/server/init.sls b/postgres/server/init.sls index daf9d1b..da744fa 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -114,7 +114,7 @@ postgresql-pg_hba: - source: {{ postgres['pg_hba.conf'] }} - template: jinja - defaults: - acls: {{ postgres.acls }} + acls: {{ postgres.acls|yaml() }} {%- if postgres.config_backup %} # Create the empty file before managing to overcome the limitation of check_cmd - onlyif: test -f {{ pg_hba_path }} || touch {{ pg_hba_path }} @@ -141,7 +141,7 @@ postgresql-pg_ident: - source: {{ postgres['pg_ident.conf'] }} - template: jinja - defaults: - mappings: {{ postgres.identity_map }} + mappings: {{ postgres.identity_map|yaml() }} {%- if postgres.config_backup %} # Create the empty file before managing to overcome the limitation of check_cmd - onlyif: test -f {{ pg_ident_path }} || touch {{ pg_ident_path }} From 8dfc5a5983ac8f06b42db038d19e3c92cdcc6bb3 Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Sat, 31 Mar 2018 21:59:31 +0100 Subject: [PATCH 07/11] Tidyup if/else in upstream.sls --- postgres/upstream.sls | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/postgres/upstream.sls b/postgres/upstream.sls index cf92872..2fae147 100644 --- a/postgres/upstream.sls +++ b/postgres/upstream.sls @@ -22,14 +22,11 @@ postgresql-repo: {%- endif -%} -{%- else -%} +{%- elif grains.os not in ('Windows', 'MacOS',) %} -# Notify that we don't manage this distro - {% if grains.os not in ('Windows', 'MacOS',) %} postgresql-repo: test.show_notification: - text: | PostgreSQL does not provide package repository for {{ grains['osfinger'] }} - {% endif %} {%- endif %} From b5e3fdd3b0bf324094618e5e7b8c723011b07a3a Mon Sep 17 00:00:00 2001 From: "Marius B. Kotsbak" Date: Thu, 3 May 2018 17:24:59 +0200 Subject: [PATCH 08/11] Better data directory permission Postgresql won't start without directory permission 0700. --- postgres/defaults.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index 2e17dd8..e3babb0 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -21,7 +21,7 @@ postgres: env: [] conf_dir: /var/lib/pgsql/data - conf_dir_mode: '0775' + conf_dir_mode: '0700' postgresconf: "" macos: From 82ef464e86d69fb1e840361d5dbc00a63401e7a0 Mon Sep 17 00:00:00 2001 From: Noel McLoughlin Date: Tue, 8 May 2018 09:40:38 +0100 Subject: [PATCH 09/11] Remove 'from_repo' in defaults & pkg_dev in codenamemap (not needed) --- postgres/codenamemap.yaml | 2 -- postgres/defaults.yaml | 2 -- 2 files changed, 4 deletions(-) diff --git a/postgres/codenamemap.yaml b/postgres/codenamemap.yaml index 6946ff2..e3f26fb 100644 --- a/postgres/codenamemap.yaml +++ b/postgres/codenamemap.yaml @@ -19,10 +19,8 @@ {% if repo.use_upstream_repo == true %} {% set version = repo.version %} {% set fromrepo = repo.fromrepo or name + '-pgdg' %} - {% set pkg_dev = '' %} {% else %} {% set fromrepo = name %} - {% set pkg_dev = 'postgresql-server-dev-all' %} {% endif %} {{ codename|default(name, true) }}: diff --git a/postgres/defaults.yaml b/postgres/defaults.yaml index fc96953..fb7fdf9 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -58,8 +58,6 @@ postgres: bake_image: False fromrepo: - pkg_repo: - name: [] users: {} tablespaces: {} From c476099a5efeb91bc2feb7717caf660d8a7ea1db Mon Sep 17 00:00:00 2001 From: Noel McLoughlin Date: Wed, 9 May 2018 17:48:09 +0100 Subject: [PATCH 10/11] Tidyup codenamemap.yaml --- postgres/codenamemap.yaml | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/postgres/codenamemap.yaml b/postgres/codenamemap.yaml index e3f26fb..59a989a 100644 --- a/postgres/codenamemap.yaml +++ b/postgres/codenamemap.yaml @@ -2,19 +2,14 @@ {% import_yaml "postgres/repo.yaml" as repo %} -{% macro debian_codename(name, version, codename=none) %} - {# - Generate lookup dictionary map for Debian and derivative distributions - - name: - distro codename - version: - PostgreSQL release version - codename: - optional grain value if `name` does not match the one returned by - `oscodename` grain + {# Generate lookup dictionary map for OS and derivative distributions + name: distro codename + version: PostgreSQL release version + codename: optional grain value if `name` does not match the one returned by `oscodename` grain #} +{% macro debian_codename(name, version, codename=none) %} + {# use upstream version if configured #} {% if repo.use_upstream_repo == true %} {% set version = repo.version %} @@ -40,21 +35,13 @@ {% macro fedora_codename(name, version, codename=none) %} - {# - Generate lookup dictionary map for Fedora distributions - - name: - distro codename - version: - PostgreSQL release version - codename: - optional grain value if `name` does not match the one returned by - `oscodename` grain - #} {# use upstream version if configured #} {% if repo.use_upstream_repo == true %} + {% set fromrepo = repo.fromrepo or name + '-pgdg' %} {% set version = repo.version %} + {% else %} + {% set fromrepo = name %} {% endif %} {{ codename|default(name, true) }}: From dd526f1de294b640dad7c51ef09aae3834858a3f Mon Sep 17 00:00:00 2001 From: Marius Kotsbak Date: Wed, 2 May 2018 15:54:53 +0200 Subject: [PATCH 11/11] Make formula relative to actual directory by using 'tpldir' --- postgres/client/init.sls | 2 +- postgres/dev.sls | 6 +++--- postgres/dropped.sls | 2 +- postgres/macos/init.sls | 2 +- postgres/macos/postgresapp.sls | 2 +- postgres/manage.sls | 4 ++-- postgres/python.sls | 2 +- postgres/server/image.sls | 2 +- postgres/server/init.sls | 2 +- postgres/upstream.sls | 4 ++-- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/postgres/client/init.sls b/postgres/client/init.sls index d315ea1..c20ecad 100644 --- a/postgres/client/init.sls +++ b/postgres/client/init.sls @@ -1,4 +1,4 @@ -{%- from "postgres/map.jinja" import postgres with context -%} +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import postgres with context -%} {%- set pkgs = [] %} {%- for pkg in (postgres.pkg_client, postgres.pkg_libpq_dev) %} diff --git a/postgres/dev.sls b/postgres/dev.sls index 7473171..7171b1f 100644 --- a/postgres/dev.sls +++ b/postgres/dev.sls @@ -1,4 +1,4 @@ -{% from "postgres/map.jinja" import postgres with context %} +{% from tpldir + "/map.jinja" import postgres with context %} {% if grains.os not in ('Windows', 'MacOS',) %} @@ -44,7 +44,7 @@ postgresql-{{ bin }}-altinstall: postgres_maxfiles_limits_conf: file.managed: - name: /Library/LaunchDaemons/limit.maxfiles.plist - - source: salt://postgres/templates/limit.maxfiles.plist + - source: salt://{{ tpldir }}/templates/limit.maxfiles.plist - context: soft_limit: {{ postgres.limits.soft or postgres.limits.hard }} hard_limit: {{ postgres.limits.hard or postgres.limits.soft }} @@ -62,7 +62,7 @@ postgres-desktop-shortcut-clean: postgres-desktop-shortcut-add: file.managed: - name: /tmp/mac_shortcut.sh - - source: salt://postgres/templates/mac_shortcut.sh + - source: salt://{{ tpldir }}/templates/mac_shortcut.sh - mode: 755 - template: jinja - context: diff --git a/postgres/dropped.sls b/postgres/dropped.sls index 8c88d7b..ffac550 100644 --- a/postgres/dropped.sls +++ b/postgres/dropped.sls @@ -1,4 +1,4 @@ -{% from "postgres/map.jinja" import postgres with context %} +{% from tpldir + "/map.jinja" import postgres with context %} postgresql-dead: service.dead: diff --git a/postgres/macos/init.sls b/postgres/macos/init.sls index ed332ad..33d33ed 100644 --- a/postgres/macos/init.sls +++ b/postgres/macos/init.sls @@ -1,4 +1,4 @@ -{% from "postgres/map.jinja" import postgres with context %} +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import postgres with context -%} include: {% if postgres.use_upstream_repo == 'postgresapp' %} diff --git a/postgres/macos/postgresapp.sls b/postgres/macos/postgresapp.sls index cb4cd4f..b1a10b3 100644 --- a/postgres/macos/postgresapp.sls +++ b/postgres/macos/postgresapp.sls @@ -1,4 +1,4 @@ -{% from "postgres/map.jinja" import postgres as pg with context %} +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import postgres as pg with context -%} # Cleanup first pg-remove-prev-archive: diff --git a/postgres/manage.sls b/postgres/manage.sls index 20a7309..1931155 100644 --- a/postgres/manage.sls +++ b/postgres/manage.sls @@ -1,5 +1,5 @@ -{%- from "postgres/map.jinja" import postgres with context -%} -{%- from "postgres/macros.jinja" import format_state with context -%} +{%- from tpldir + "/map.jinja" import postgres with context -%} +{%- from tpldir + "/macros.jinja" import format_state with context -%} {%- if salt['postgres.user_create']|default(none) is not callable %} diff --git a/postgres/python.sls b/postgres/python.sls index 171062c..e007264 100644 --- a/postgres/python.sls +++ b/postgres/python.sls @@ -1,4 +1,4 @@ -{% from "postgres/map.jinja" import postgres with context %} +{% from tpldir + "/map.jinja" import postgres with context %} postgresql-python: pkg.installed: diff --git a/postgres/server/image.sls b/postgres/server/image.sls index 95838e7..711347f 100644 --- a/postgres/server/image.sls +++ b/postgres/server/image.sls @@ -1,4 +1,4 @@ -{%- from "postgres/map.jinja" import postgres with context -%} +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import postgres with context -%} # This state is used to launch PostgreSQL with ``pg_ctl`` command and enable it # on "boot" during an image (Docker, Virtual Appliance, AMI) preparation diff --git a/postgres/server/init.sls b/postgres/server/init.sls index 60934c3..ace913d 100644 --- a/postgres/server/init.sls +++ b/postgres/server/init.sls @@ -1,4 +1,4 @@ -{%- from "postgres/map.jinja" import postgres with context %} +{%- from salt.file.dirname(tpldir) ~ "/map.jinja" import postgres with context -%} {%- set includes = [] %} {%- if postgres.bake_image %} diff --git a/postgres/upstream.sls b/postgres/upstream.sls index 2fae147..45605c4 100644 --- a/postgres/upstream.sls +++ b/postgres/upstream.sls @@ -1,5 +1,5 @@ -{%- from "postgres/map.jinja" import postgres with context -%} -{%- from "postgres/macros.jinja" import format_kwargs with context -%} +{%- from tpldir + "/map.jinja" import postgres with context -%} +{%- from tpldir + "/macros.jinja" import format_kwargs with context -%} {%- if 'pkg_repo' in postgres -%}