Commit 5f48f9ef authored by viscapi's avatar viscapi
Browse files

Merge branch 'separate-postgres-tasks-by-platform' into 'master'

Separate postgres tasks by platform

See merge request !3
parents 818d9e4b 9e61ee6e
---
- name: Check that the database doesn't exist yet on CentOS
stat:
path: "{{path_to_icat}}/postgresql.conf"
register: stat_result_centos
- 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_major_version'] == "7"
- stat_result_centos.stat.exists == False
- 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_major_version'] == "7"
- stat_result_centos.stat.exists == False
- 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_major_version'] == "8"
- stat_result_centos.stat.exists == False
- 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_major_version'] == "8"
- stat_result_centos.stat.exists == False
- use_distribution_postgresql
...
---
# tasks file for postgresql
- import_tasks: repos.yml
- import_tasks: packages.yml
- import_tasks: ../common/pip.yml
- import_tasks: ../common/users.yml
- import_tasks: users.yml
- import_tasks: ../common/files.yml
- import_tasks: db_init.yml
- import_tasks: patches.yml
- import_tasks: security.yml
- import_tasks: ../common/systemd.yml
- import_tasks: ../common/db_privs.yml
...
......@@ -7,7 +7,9 @@
- 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"
- use_external_epel
- name: Install ancillary packages for CentOS 7
yum:
......@@ -15,7 +17,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 +26,9 @@
- '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"
- not use_distribution_postgresql
- name: Install PostgreSQL 9.2 packages for CentOS 7
yum:
......@@ -33,7 +37,9 @@
- 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"
- use_distribution_postgresql
- name: Install ancillary packages for CentOS 8
dnf:
......@@ -42,11 +48,13 @@
- 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"
- not use_distribution_postgresql
- name: Install PostgreSQL {{ external_postgresql_version }} packages for CentOS 8
dnf:
......@@ -55,7 +63,9 @@
- '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"
- not use_distribution_postgresql
- name: Install PostgreSQL 10 packages for CentOS 8
dnf:
......@@ -64,20 +74,8 @@
- 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"
- 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
...
......@@ -5,7 +5,9 @@
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"
- not use_distribution_postgresql
- name: Install external PostgreSQL repository for CentOS 8
dnf:
......@@ -13,7 +15,8 @@
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"
- 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"
...
---
- name: Create UNIX iRODS group
group:
name: "{{ irods_unix_group_name }}"
gid: "{{ irods_unix_group_id }}"
state: present
- name: Create UNIX iRODS user
user:
name: "{{ irods_unix_user_name }}"
uid: "{{ irods_unix_user_id }}"
group: irods
state: present
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
......@@ -31,6 +16,7 @@
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: Create UNIX iRODS group
group:
name: "{{ irods_unix_group_name }}"
gid: "{{ irods_unix_group_id }}"
state: present
- name: Create UNIX iRODS user
user:
name: "{{ irods_unix_user_name }}"
uid: "{{ irods_unix_user_id }}"
group: irods
state: present
password: "{{irods_unix_password}}"
#password: see docs.ansible.com/ansible/latest/user_module.html
...
---
- 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)
...
---
- 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
- 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_major_version'] == "10"
- stat_result_debian.stat.exists == False
...
---
# tasks file for postgresql
- import_tasks: ../common/pip.yml
- import_tasks: ../common/users.yml
- import_tasks: ../common/files.yml
- import_tasks: db_init.yml
- import_tasks: ../common/systemd.yml
- import_tasks: ../common/db_privs.yml
...
---
# tasks file for postgresql
- name: Postgresql deployment for Centos.
import_tasks: centos/main.yml
when: ansible_facts['distribution'] == "CentOS"
- 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: Postgresql deployment for Ubuntu.
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"
...
......@@ -12,6 +12,7 @@
- name: Print PostgreSQL version
debug:
var: postgresql_version.version.major
when: (ansible_facts['distribution'] == "Ubuntu" and ansible_facts['distribution_major_version'] == "18")
when:
- ansible_facts['distribution_major_version'] == "18"
...
---
- 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
- 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_major_version'] == "18"
- stat_result_ubuntu.stat.exists == False
...
---
# tasks file for postgresql
- import_tasks: packages.yml
- import_tasks: ../common/pip.yml
- import_tasks: ../common/users.yml
- import_tasks: users.yml
- import_tasks: ../common/files.yml
- import_tasks: db_info.yml
- import_tasks: db_init.yml
- import_tasks: patches.yml
- import_tasks: ../common/systemd.yml
- import_tasks: ../common/db_privs.yml
...
---
- name: Install ancillary packages for Ubuntu 18.04
apt:
name:
- python-apt
- python-pip
state: present
when:
- ansible_facts['distribution_major_version'] == "18"
- name: Install PostgreSQL 10 packages for Ubuntu 18.04
apt:
name: postgresql
state: present
when:
- ansible_facts['distribution_major_version'] == "18"
- use_distribution_postgresql
...
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