Commit fc98d002 authored by Louis VINCHON's avatar Louis VINCHON
Browse files

Role postgresql: clean up the 'debian' tasks

Remove anything that is not Debian-specific in the 'debian' folder.
parent c9f541c0
---
- 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")
...
---
- name: Check that the database doesn't exist yet on CentOS
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)
- 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)
- 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)
- 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'] == "10" and stat_result_debian.stat.exists == False)
...
......@@ -2,16 +2,15 @@
# tasks file for postgresql
- 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
...
---
- name: Install EPEL repository
yum:
conf_file: '/etc/yum.conf'
name:
- epel-release
state: present
update_cache: yes
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and use_external_epel)
- name: Install ancillary packages for CentOS 7
yum:
conf_file: '/etc/yum.conf'
name:
- libselinux-python
- python-pip
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7")
- name: Install PostgreSQL {{ external_postgresql_version }} packages for CentOS 7
yum:
conf_file: '/etc/yum.conf'
name:
- '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)
- name: Install PostgreSQL 9.2 packages for CentOS 7
yum:
conf_file: '/etc/yum.conf'
name:
- postgresql
- postgresql-server
state: present
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7" and use_distribution_postgresql)
- name: Install ancillary packages for CentOS 8
dnf:
conf_file: '/etc/dnf/dnf.conf'
name:
- python3-libselinux
- python3-pip
state: present
when: (ansible_facts['distribution'] == "CentOS" and 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)
- name: Install PostgreSQL {{ external_postgresql_version }} packages for CentOS 8
dnf:
conf_file: '/etc/dnf/dnf.conf'
name:
- '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)
- name: Install PostgreSQL 10 packages for CentOS 8
dnf:
conf_file: '/etc/dnf/dnf.conf'
name:
- 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)
...
---
- name: Configure PostgreSQL listen address and authorization in pg_hba.conf on CentOS
block:
- name: Configure PostgreSQL listen address on CentOS
lineinfile:
path: "{{ path_to_icat }}/postgresql.conf"
regexp: '^#listen_addresses ='
line: 'listen_addresses = {{ ansible_nodename }}'
backrefs: yes
backup: yes
- name: Set authorization in pg_hba.conf on CentOS
postgresql_pg_hba:
dest: "{{ path_to_icat }}/pg_hba.conf"
databases: "{{ database_name }}"
users: "{{ database_user }}"
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")
...
---
- name: Install external PostgreSQL repository for CentOS 7
yum:
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)
- name: Install external PostgreSQL repository for CentOS 8
dnf:
conf_file: '/etc/dnf/dnf.conf'
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)
...
---
- name: Set SELinux mode on CentOS
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"
...
......@@ -15,22 +15,4 @@
password: "{{irods_unix_password}}"
#password: see docs.ansible.com/ansible/latest/user_module.html
- name: Create postgres user and group on CentOS 7
block:
- name: Create UNIX postgres group
group:
name: "{{ postgresql_unix_group_name }}"
state: present
system: yes
- name: Create UNIX postgres user
user:
name: "{{ postgresql_unix_user_name }}"
group: "{{ postgresql_unix_group_name }}"
state: present
system: yes
shell: /usr/bin/false
create_home: no
when: (ansible_facts['distribution'] == "CentOS" and ansible_facts['distribution_major_version'] == "7")
...
......@@ -8,4 +8,8 @@
import_tasks: ubuntu/main.yml
when: ansible_facts['distribution'] == "Ubuntu"
- name: Postgresql deployment for Debian.
import_tasks: debian/main.yml
when: ansible_facts['distribution'] == "Debian"
...
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