diff --git a/playbooks/postgresql_server.yml b/playbooks/postgresql_server.yml new file mode 100644 index 000000000..f9b4092b9 --- /dev/null +++ b/playbooks/postgresql_server.yml @@ -0,0 +1,9 @@ +--- +- hosts: all + gather_facts: true + become: true + roles: + - role: update_os_packages + - role: postgresql_scl + when: ansible_distribution_major_version == '7' + - role: external_database diff --git a/roles/external_database/tasks/main.yml b/roles/external_database/tasks/main.yml new file mode 100644 index 000000000..8c7cad924 --- /dev/null +++ b/roles/external_database/tasks/main.yml @@ -0,0 +1,91 @@ +--- +- name: "Load OS variables" + include_vars: "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml" + +- name: 'Install PostgreSQL packages' + package: + name: "{{ external_database_packages }}" + state: installed + +- name: 'Init PostgreSQL database' + command: postgresql-setup initdb + args: + creates: "{{ external_database_postgresql_conf_path }}" + +- name: 'Deploy pg_hba.conf' + copy: + dest: "{{ external_database_pg_hba_conf_path }}" + content: | + # TYPE DATABASE USER ADDRESS METHOD + + # "local" is for Unix domain socket connections only + local all all ident + + # IPv4 local connections: + host all all 127.0.0.1/32 md5 + + # IPv4 remote connections: + host all all 0.0.0.0/0 md5 + + # IPv6 local connections: + host all all ::1/128 md5 + force: yes + mode: 0600 + owner: postgres + group: postgres + +- name: Set listen addresses to * + lineinfile: + dest: "{{ external_database_postgresql_conf_path }}" + regexp: "^listen_addresses" + line: "listen_addresses = '*'" + state: present + backup: yes + +- name: 'Ensure PostgreSQL is running' + service: + name: postgresql + state: restarted + enabled: yes + +- name: 'Add database user' + become_user: postgres + postgresql_user: + state: present + name: "foreman" + password: "foreman" + +- name: 'Create Foreman database' + become_user: postgres + postgresql_db: + state: present + name: "foreman" + owner: "foreman" + +- name: 'Add candlepin database user' + become_user: postgres + postgresql_user: + state: present + name: "candlepin" + password: "candlepin" + +- name: 'Create Candlepin database' + become_user: postgres + postgresql_db: + state: present + name: "candlepin" + owner: "candlepin" + +- name: 'Add pulp database user' + become_user: postgres + postgresql_user: + state: present + name: "pulp" + password: "pulp" + +- name: 'Create Pulp database' + become_user: postgres + postgresql_db: + state: present + name: "pulp" + owner: "pulp" diff --git a/roles/external_database/vars/RedHat-7.yml b/roles/external_database/vars/RedHat-7.yml new file mode 100644 index 000000000..6fbc528e5 --- /dev/null +++ b/roles/external_database/vars/RedHat-7.yml @@ -0,0 +1,7 @@ +--- +external_database_packages: + - rh-postgresql12-syspaths + - rh-postgresql12-postgresql-server + - python-psycopg2 +external_database_postgresql_conf_path: /var/opt/rh/rh-postgresql12/lib/pgsql/data/postgresql.conf +external_database_pg_hba_conf_path: /var/opt/rh/rh-postgresql12/lib/pgsql/data/pg_hba.conf diff --git a/roles/external_database/vars/RedHat-8.yml b/roles/external_database/vars/RedHat-8.yml new file mode 100644 index 000000000..2504e8ba5 --- /dev/null +++ b/roles/external_database/vars/RedHat-8.yml @@ -0,0 +1,6 @@ +--- +external_database_packages: + - postgresql-server + - python3-psycopg2 +external_database_postgresql_conf_path: /var/lib/pgsql/data/postgresql.conf +external_database_pg_hba_conf_path: /var/lib/pgsql/data/pg_hba.conf