diff --git a/postgres/client.sls b/postgres/client/init.sls similarity index 87% rename from postgres/client.sls rename to postgres/client/init.sls index 473f3c6..c20ecad 100644 --- a/postgres/client.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) %} @@ -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/codenamemap.yaml b/postgres/codenamemap.yaml index 0b049e2..59a989a 100644 --- a/postgres/codenamemap.yaml +++ b/postgres/codenamemap.yaml @@ -2,28 +2,27 @@ {% 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 %} + {% set fromrepo = repo.fromrepo or name + '-pgdg' %} + {% else %} + {% set fromrepo = name %} {% 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 @@ -36,25 +35,18 @@ {% 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) }}: # 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 aff9607..3a66a15 100644 --- a/postgres/defaults.yaml +++ b/postgres/defaults.yaml @@ -21,6 +21,7 @@ postgres: env: [] conf_dir: /var/lib/pgsql/data + conf_dir_mode: '0700' postgresconf: "" macos: @@ -56,6 +57,8 @@ postgres: bake_image: False + fromrepo: + users: {} tablespaces: {} databases: {} diff --git a/postgres/dev.sls b/postgres/dev.sls index c9f330b..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',) %} @@ -6,18 +6,37 @@ 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 %} +# 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 %} @@ -25,7 +44,7 @@ install-postgres-libpq-dev: 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 }} @@ -43,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/osfamilymap.yaml b/postgres/osfamilymap.yaml index 6d241ac..2a57781 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 @@ -56,6 +57,8 @@ RedHat: # directory containing PostgreSQL client executables bin_dir: /usr/pgsql-{{ repo.version }}/bin + dev_bins: + - ecg client_bins: - clusterdb - createdb @@ -112,6 +115,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 @@ -129,6 +133,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/python.sls b/postgres/python.sls index e66600d..4a5ee21 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 %} include: - postgres.upstream 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/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 6e2b23b..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 %} @@ -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: @@ -40,8 +43,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 }} @@ -72,7 +76,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: @@ -114,7 +118,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 +145,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 }} diff --git a/postgres/upstream.sls b/postgres/upstream.sls index cf92872..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 -%} @@ -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 %}