Commit 1ca3b3ad authored by Louis VINCHON's avatar Louis VINCHON
Browse files

Role postgresql: clean up the 'centos' tasks

Remove anything that is not CentOS-specific in the 'centos' folder.

Add a task import for the tasks/centos/main.yml file in the tasks/main.yml
file.
With this we effectively have factorized all CentOS distribution checks into
only one check.
parent 05ad35f0
---
- name: Collect and print PostgreSQL version on Ubuntu
block:
- name: Collect PostgreSQL version
become: yes
become_user: postgres
postgresql_info:
filter: ver*
register: postgresql_version
- name: Print PostgreSQL version
debug:
var: postgresql_version.version.major
when: (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "18")
...
......@@ -4,54 +4,29 @@
stat:
path: "{{path_to_icat}}/postgresql.conf"
register: stat_result_centos
when: ansible_facts['distribution'] == "CentOS"
- name: Check that the database doesn't exist yet on Debian
stat:
path: "/etc/postgresql/{{ postgresql_version.version.major }}/{{ cluster_name }}/postgresql.conf"
register: stat_result_debian
when: ansible_facts['distribution'] == "Debian"
- name: Check that the database doesn't exist yet on Ubuntu
stat:
path: "/etc/postgresql/{{ postgresql_version.version.major }}/{{ cluster_name }}/postgresql.conf"
register: stat_result_ubuntu
when: ansible_facts['distribution'] == "Ubuntu"
- name: Initialization of ICAT database on CentOS 7
command: /usr/pgsql-{{ external_postgresql_version }}/bin/initdb -D {{path_to_icat}}
become: true
become_user: postgres
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and stat_result_centos.stat.exists == False and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "7" and stat_result_centos.stat.exists == False and not use_distribution_postgresql)
- name: Initialization of ICAT database on CentOS 7
command: /usr/bin/initdb -D {{path_to_icat}}
become: true
become_user: postgres
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and stat_result_centos.stat.exists == False and use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "7" and stat_result_centos.stat.exists == False and use_distribution_postgresql)
- name: Initialization of ICAT database on CentOS 8
command: /usr/pgsql-{{ external_postgresql_version }}/bin/initdb -D {{path_to_icat}}
become: true
become_user: postgres
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and stat_result_centos.stat.exists == False and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "8" and stat_result_centos.stat.exists == False and not use_distribution_postgresql)
- name: Initialization of ICAT database on CentOS 8
command: /usr/bin/initdb -D {{path_to_icat}}
become: true
become_user: postgres
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and stat_result_centos.stat.exists == False and use_distribution_postgresql)
- name: Initialization of ICAT database on Debian 10
command: /usr/bin/pg_createcluster -d {{ path_to_icat }} {{ postgresql_version.version.major }} {{ cluster_name }}
become: true
become_user: postgres
when: (ansible_facts['distribution'] == "Debian" and ansible_facts['distribution_major_version'] == "10" and stat_result_debian.stat.exists == False)
- name: Initialization of ICAT database on Ubuntu 18.04
command: /usr/bin/pg_createcluster -d {{ path_to_icat }} {{ postgresql_version.version.major }} {{ cluster_name }}
become: true
become_user: postgres
when: (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "18" and stat_result_ubuntu.stat.exists == False)
when: (ansible_facts['distribution_major_version'] == "8" and stat_result_centos.stat.exists == False and use_distribution_postgresql)
...
......@@ -5,13 +5,17 @@
- import_tasks: repos.yml
- import_tasks: packages.yml
- import_tasks: pip.yml
- import_tasks: users.yml
- import_tasks: files.yml
- import_tasks: db_info.yml
- import_tasks: db_init.yml
- import_tasks: patches.yml
- import_tasks: security.yml
- import_tasks: systemd.yml
- import_tasks: db_privs.yml
...
......@@ -7,7 +7,7 @@
- epel-release
state: present
update_cache: yes
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and use_external_epel)
when: (ansible_facts['distribution_major_version'] == "7" and use_external_epel)
- name: Install ancillary packages for CentOS 7
yum:
......@@ -15,7 +15,7 @@
name:
- libselinux-python
- python-pip
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7")
when: ansible_facts['distribution_major_version'] == "7"
- name: Install PostgreSQL {{ external_postgresql_version }} packages for CentOS 7
yum:
......@@ -24,7 +24,7 @@
- 'postgresql{{ external_postgresql_version | replace(".", "") }}'
- 'postgresql{{ external_postgresql_version | replace(".", "") }}-server'
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "7" and not use_distribution_postgresql)
- name: Install PostgreSQL 9.2 packages for CentOS 7
yum:
......@@ -33,7 +33,7 @@
- postgresql
- postgresql-server
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "7" and use_distribution_postgresql)
- name: Install ancillary packages for CentOS 8
dnf:
......@@ -42,11 +42,11 @@
- python3-libselinux
- python3-pip
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8")
when: ansible_facts['distribution_major_version'] == "8"
- name: Disable the built-in PostgreSQL module
command: dnf -qy module disable postgresql
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
- name: Install PostgreSQL {{ external_postgresql_version }} packages for CentOS 8
dnf:
......@@ -55,7 +55,7 @@
- 'postgresql{{ external_postgresql_version | replace(".", "") }}'
- 'postgresql{{ external_postgresql_version | replace(".", "") }}-server'
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
- name: Install PostgreSQL 10 packages for CentOS 8
dnf:
......@@ -64,20 +64,6 @@
- postgresql
- postgresql-server
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and use_distribution_postgresql)
- name: Install ancillary packages for Ubuntu 18.04
apt:
name:
- python-apt
- python-pip
state: present
when: (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "18")
- name: Install PostgreSQL 10 packages for Ubuntu 18.04
apt:
name: postgresql
state: present
when: (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "18" and use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "8" and use_distribution_postgresql)
...
......@@ -18,39 +18,5 @@
address: "{{ provider_ip }}/24"
contype: host
method: trust
when: (ansible_facts['distribution'] == "CentOS")
- name: Configure PostgreSQL listen address and authorization in pg_hba.conf on Ubuntu
block:
# - name: Configure hostname on Ubuntu
# hostname:
# name: "{{ ansible_hostname }}.{{ domain_name }}"
# use: systemd
# - name: Configure /etc/hosts on Ubuntu
# lineinfile:
# path: /etc/hosts
# insertafter: EOF
# line: "{{ ansible_default_ipv4.address }}\t{{ ansible_nodename }}\t{{ ansible_hostname }}"
# backup: yes
# state: present
- name: Configure PostgreSQL listen address on Ubuntu
lineinfile:
path: "/etc/postgresql/{{ postgresql_version.version.major }}/{{ cluster_name }}/postgresql.conf"
regexp: '^#listen_addresses ='
line: 'listen_addresses = {{ ansible_nodename }}'
backrefs: yes
backup: yes
- name: Set autorization in pg_hba.conf on Ubuntu
postgresql_pg_hba:
dest: /etc/postgresql/{{ postgresql_version.version.major }}/{{ cluster_name }}/pg_hba.conf
databases: "{{ database_name }}"
users: "{{ database_user }}"
address: "{{ provider_ip }}/24"
contype: host
method: trust
when: (ansible_facts['distribution'] == "Ubuntu")
...
......@@ -5,7 +5,7 @@
conf_file: '/etc/yum.conf'
name: https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "7" and not use_distribution_postgresql)
- name: Install external PostgreSQL repository for CentOS 8
dnf:
......@@ -13,7 +13,7 @@
name: https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
state: present
disable_gpg_check: yes
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
when: (ansible_facts['distribution_major_version'] == "8" and not use_distribution_postgresql)
...
......@@ -4,17 +4,14 @@
selinux:
policy: targeted
state: "{{ selinux_mode }}"
when: ansible_facts['distribution'] == "CentOS"
- name: Allow PostgreSQL to modify files in "{{ path_to_icat }}" on CentOS
sefcontext:
target: '{{ path_to_icat }}(/.*)?'
setype: postgresql_db_t
state: present
when: ansible_facts['distribution'] == "CentOS"
- name: Apply new SELinux file context to filesystem
command: restorecon -irv "{{ path_to_icat }}"
when: ansible_facts['distribution'] == "CentOS"
...
......@@ -31,6 +31,6 @@
system: yes
shell: /usr/bin/false
create_home: no
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7")
when: ansible_facts['distribution_major_version'] == "7"
...
---
- name: Postgresql deployment for Centos.
import_tasks: centos/main.yml
when: ansible_facts['distribution'] == "CentOS"
...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment