-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add role to spin up a basic external postgresql database
- Loading branch information
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |