From 1a7a45a131a14453bff6cc983cb536b40cf5506f Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Mon, 9 Nov 2020 21:00:15 +0100 Subject: [PATCH] Update to 2020-11-09 21:00 --- roles/postgresql_server/meta/main.yml | 4 +++ roles/postgresql_server/tasks/main.yml | 35 +++++++--------------- roles/postgresql_server/vars/CentOS-7.yml | 7 +++++ roles/postgresql_server/vars/CentOS-8.yml | 7 +++++ roles/repo_postgresql/defaults/main.yml | 5 ++++ roles/repo_postgresql/tasks/main.yml | 8 +++++ roles/repo_postgresql/templates/postgresql.repo.j2 | 11 +++++++ 7 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 roles/postgresql_server/meta/main.yml create mode 100644 roles/postgresql_server/vars/CentOS-7.yml create mode 100644 roles/postgresql_server/vars/CentOS-8.yml create mode 100644 roles/repo_postgresql/defaults/main.yml create mode 100644 roles/repo_postgresql/tasks/main.yml create mode 100644 roles/repo_postgresql/templates/postgresql.repo.j2 diff --git a/roles/postgresql_server/meta/main.yml b/roles/postgresql_server/meta/main.yml new file mode 100644 index 0000000..764e728 --- /dev/null +++ b/roles/postgresql_server/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: repo_postgresql diff --git a/roles/postgresql_server/tasks/main.yml b/roles/postgresql_server/tasks/main.yml index 2cc493e..046853a 100644 --- a/roles/postgresql_server/tasks/main.yml +++ b/roles/postgresql_server/tasks/main.yml @@ -1,31 +1,16 @@ --- -- name: Configure PostgreSQL repository - yum_repository: - name: postgresql - description: PostgreSQL - baseurl: https://download.postgresql.org/pub/repos/yum/{{ pg_version }}/redhat/rhel-$releasever-$basearch - gpgcheck: True - gpgkey: https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-{{ pg_version }} - state: "{{ (pg_version != 'default') | ternary('present','absent') }}" - register: pg_repo - tags: pg,repo - -- name: Clear PostgreSQL repo cache - file: path=/var/cache/yum/{{ ansible_architecture }}/{{ ansible_distribution_major_version }}/postgresql/{{ item }} state=absent - loop: - - cachecookie - - repomd.xml - when: pg_repo.changed - tags: pg - -- name: Install dependencies +- include_vars: "{{ item }}" + with_first_found: + - vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml + - vars/{{ ansible_distribution }}.yml + - vars/{{ ansible_os_family }}.yml + - vars/defaults.yml + tags: pg + +- name: Install Postgresql packages yum: - name: - - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }} - - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }}-server - - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }}-contrib - - python-psycopg2 + name: "{{ pg_packages }}" tags: pg - name: Check if PG_VERSION exists diff --git a/roles/postgresql_server/vars/CentOS-7.yml b/roles/postgresql_server/vars/CentOS-7.yml new file mode 100644 index 0000000..93d5979 --- /dev/null +++ b/roles/postgresql_server/vars/CentOS-7.yml @@ -0,0 +1,7 @@ +--- + +pg_packages: + - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }} + - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }}-server + - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }}-contrib + - python-psycopg2 diff --git a/roles/postgresql_server/vars/CentOS-8.yml b/roles/postgresql_server/vars/CentOS-8.yml new file mode 100644 index 0000000..3fde919 --- /dev/null +++ b/roles/postgresql_server/vars/CentOS-8.yml @@ -0,0 +1,7 @@ +--- + +pg_packages: + - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }} + - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }}-server + - postgresql{{ (pg_version != 'default') | ternary(pg_version | string,'') }}-contrib + - python3-psycopg2 diff --git a/roles/repo_postgresql/defaults/main.yml b/roles/repo_postgresql/defaults/main.yml new file mode 100644 index 0000000..a5860d8 --- /dev/null +++ b/roles/repo_postgresql/defaults/main.yml @@ -0,0 +1,5 @@ +--- + +# Version of postgres to install. 'default' means takes the one from the standard repo +# If a version is specified (like 10, 11, 12, 13 etc.), upstream repository will be configured +pg_version: default diff --git a/roles/repo_postgresql/tasks/main.yml b/roles/repo_postgresql/tasks/main.yml new file mode 100644 index 0000000..9db788f --- /dev/null +++ b/roles/repo_postgresql/tasks/main.yml @@ -0,0 +1,8 @@ +--- + + # Here we use a template instead of yum_repository because + # we might need to set module_hotfixes = true for el8. And yum_repository + # doesn't support this setting +- name: Configure Postgres repo + template: src=postgresql.repo.j2 dest=/etc/yum.repos.d/postgresql.repo + tags: pg,repo diff --git a/roles/repo_postgresql/templates/postgresql.repo.j2 b/roles/repo_postgresql/templates/postgresql.repo.j2 new file mode 100644 index 0000000..93d8115 --- /dev/null +++ b/roles/repo_postgresql/templates/postgresql.repo.j2 @@ -0,0 +1,11 @@ +{% if pg_version != 'default' %} +[postgresql] +baseurl = https://download.postgresql.org/pub/repos/yum/{{ pg_version }}/redhat/rhel-$releasever-$basearch +gpgcheck = 1 +gpgkey = https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG-{{ pg_version }} +name = PostgreSQL +{% if ansible_os_family == 'RedHat' and ansible_distribution_major_version is version('8', '>=') %} +# Workaround a bug in dnf which would make the default module mask packages from postgres repo +module_hotfixes = true +{% endif %} +{% endif %}