Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role to spin up a basic external postgresql database #1502

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playbooks/fips.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- hosts: all
become: yes
gather_facts: no
gather_facts: yes
roles:
- fips
9 changes: 9 additions & 0 deletions playbooks/postgresql_server.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions roles/external_database/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
external_database_encryption: md5
4 changes: 4 additions & 0 deletions roles/external_database/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
dependencies:
- role: foreman_repositories
- role: katello_repositories
85 changes: 85 additions & 0 deletions roles/external_database/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
- 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'
template:
dest: "{{ external_database_pg_hba_conf_path }}"
src: pg_hba.conf.j2
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: Set password_encryption
lineinfile:
dest: "{{ external_database_postgresql_conf_path }}"
regexp: "password_encryption ="
line: "password_encryption = {{ external_database_encryption }}"
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"
13 changes: 13 additions & 0 deletions roles/external_database/templates/pg_hba.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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 {{ external_database_encryption }}

# IPv4 remote connections:
host all all 0.0.0.0/0 {{ external_database_encryption }}

# IPv6 local connections:
host all all ::1/128 {{ external_database_encryption }}
8 changes: 8 additions & 0 deletions roles/external_database/vars/RedHat-7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
external_database_packages:
- rh-postgresql12-syspaths
- rh-postgresql12-postgresql-server
- python-psycopg2
- rh-postgresql12-postgresql-evr
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
7 changes: 7 additions & 0 deletions roles/external_database/vars/RedHat-8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
external_database_packages:
- postgresql-server
- python3-psycopg2
- postgresql-evr
external_database_postgresql_conf_path: /var/lib/pgsql/data/postgresql.conf
external_database_pg_hba_conf_path: /var/lib/pgsql/data/pg_hba.conf
10 changes: 10 additions & 0 deletions vagrant/boxes.d/00-centos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ boxes:
- foreman
- katello

centos8-stream-fips:
box_name: 'centos/stream8'
disk_size: 40
pty: true
scenarios:
- foreman
- katello
ansible:
playbook: 'playbooks/fips.yml'

centos9-stream:
box_name: 'centos/stream9'
disk_size: 40
Expand Down