diff --git a/pipelines/external_database.yml b/pipelines/external_database.yml new file mode 100644 index 000000000..1e0021c49 --- /dev/null +++ b/pipelines/external_database.yml @@ -0,0 +1,43 @@ +- hosts: localhost + vars_files: + - vars/external_database.yml + roles: + - forklift + +- hosts: "{{ forklift_database_name }}" + become: yes + vars_files: + - vars/external_database.yml + roles: + - role: forklift_versions + scenario: "{{ pipeline_type }}" + scenario_os: "{{ pipeline_os }}" + scenario_version: "{{ pipeline_version }}" + - role: postgresql + +- hosts: "{{ forklift_server_name }}" + become: yes + vars_files: + - vars/external_database.yml + roles: + - role: forklift_versions + scenario: "{{ pipeline_type }}" + scenario_os: "{{ pipeline_os }}" + scenario_version: "{{ pipeline_version }}" + - role: foreman_server_repositories + - role: etc_hosts + - role: update_os_packages + - role: foreman_installer + foreman_installer_options_internal_use_only: + - "--foreman-db-manage false" + - "--foreman-db-host {{ forklift_database_name }}" + - "--foreman-db-database foreman" + - "--foreman-db-password foreman" + - "--katello-candlepin-manage-db false" + - "--katello-candlepin-db-host {{ forklift_database_name }}" + - "--katello-candlepin-db-name candlepin" + - "--katello-candlepin-db-password candlepin" + - "--foreman-proxy-content-pulpcore-manage-postgresql false" + - "--foreman-proxy-content-pulpcore-postgresql-host {{ forklift_database_name }}" + - "--foreman-proxy-content-pulpcore-postgresql-db-name pulp" + - "--foreman-proxy-content-pulpcore-postgresql-password pulp" diff --git a/pipelines/vars/external_database.yml b/pipelines/vars/external_database.yml new file mode 100644 index 000000000..3c04a8b24 --- /dev/null +++ b/pipelines/vars/external_database.yml @@ -0,0 +1,25 @@ +pipeline_type: katello +pipeline_version: nightly +pipeline_os: centos9-stream +foreman_installer_scenario: katello +server_box: + box: "{{ pipeline_os }}" + memory: 10240 + ansible: + variables: + foreman_server_repositories_katello: true + foreman_installer_disable_system_checks: true + foreman_installer_scenario: katello + foreman_installer_additional_packages: + - "foreman-installer-katello" +database_box: + box: "{{ pipeline_os }}" + memory: 4096 + ansible: + variables: + postgresql_use_evr: true +forklift_name: "pi-{{ pipeline_type }}-{{ pipeline_version }}-{{ pipeline_os }}-external-database" +forklift_server_name: "pi-{{ pipeline_type }}-{{ pipeline_version }}-{{ pipeline_os }}-server" +forklift_database_name: "pi-{{ pipeline_type }}-{{ pipeline_version }}-{{ pipeline_os }}-database" +forklift_boxes: + "{{ {forklift_server_name: server_box, forklift_database_name: database_box} }}" diff --git a/playbooks/external_database.yml b/playbooks/external_database.yml new file mode 100644 index 000000000..74cc43f22 --- /dev/null +++ b/playbooks/external_database.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + become: true + roles: + - postgresql diff --git a/roles/postgresql/tasks/main.yml b/roles/postgresql/tasks/main.yml new file mode 100644 index 000000000..e7d19e51b --- /dev/null +++ b/roles/postgresql/tasks/main.yml @@ -0,0 +1,103 @@ +--- +- name: 'Install postgres packages' + yum: + name: "{{ item }}" + state: installed + with_items: + - postgresql-server + - python-psycopg2 + - postgresql-contrib + +- when: postgresql_use_evr + block: + - name: Include foreman server repositories + include_role: + name: katello_repositories + + - name: 'Install postgresql-evr packages' + yum: + name: postgresql-evr + state: installed + +- name: 'Init PostgreSQL database' + command: postgresql-setup initdb + args: + creates: /var/lib/pgsql/data/postgresql.conf + +- name: 'Deploy pg_hba.conf' + copy: + dest: /var/lib/pgsql/data/pg_hba.conf + 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: /var/lib/pgsql/data/postgresql.conf + 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"