-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OPSEXP-2637: refactor postgres role to generate syncservice database …
…credentials only when needed (#894)
- Loading branch information
Showing
11 changed files
with
227 additions
and
122 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
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
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
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
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,28 @@ | ||
--- | ||
argument_specs: | ||
setup_db: | ||
short_description: Configure PostgreSQL database | ||
options: | ||
postgres_db_name: | ||
type: str | ||
required: true | ||
description: | | ||
Name of the database to be created | ||
postgres_db_username: | ||
type: str | ||
required: true | ||
description: | | ||
Username of the database user | ||
postgres_db_password: | ||
type: str | ||
required: true | ||
description: | | ||
Password of the database user | ||
postgres_db_clients: | ||
type: list | ||
elements: str | ||
required: true | ||
description: | | ||
List of clients that are allowed to connect to the database | ||
Each client must be an host inventory for which facts have been | ||
gathered (in particular ansible_default_ipv4.address) |
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
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
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,63 @@ | ||
--- | ||
- name: Include OS specific variables | ||
ansible.builtin.include_vars: "{{ item }}" | ||
loop: >- | ||
{{ lookup('first_found', os_fallback, errors='ignore', wantlist=True) }} | ||
- name: Configure PostgreSQL client auth | ||
become: true | ||
notify: | ||
- Restart-postgresql | ||
ansible.builtin.blockinfile: | ||
path: "{{ postgresql_conf_path }}/pg_hba.conf" | ||
block: | | ||
{% for host in postgres_db_clients | map('extract', hostvars, ['ansible_default_ipv4', 'address']) %} | ||
host {{ postgres_db_name }} {{ postgres_db_username }} {{ host }}/32 md5 | ||
{% endfor %} | ||
marker: >- | ||
# {mark} ANSIBLE MANAGED: allow {{ postgres_db_clients | join(", ") }} to connect to {{ postgres_db_name }} as {{ postgres_db_username }} | ||
owner: postgres | ||
group: postgres | ||
mode: "u=rw" | ||
|
||
- name: Configure PostgreSQL database | ||
become: true | ||
become_user: postgres | ||
vars: | ||
ansible_ssh_pipelining: true | ||
block: | ||
- name: Create database | ||
community.postgresql.postgresql_db: | ||
name: "{{ postgres_db_name }}" | ||
|
||
- name: Revoke default access to public schema | ||
community.postgresql.postgresql_privs: | ||
db: "{{ postgres_db_name }}" | ||
privs: ALL | ||
type: schema | ||
objs: public | ||
role: public | ||
state: absent | ||
tags: | ||
- molecule-idempotence-notest | ||
|
||
- name: Create unprivileged user | ||
community.postgresql.postgresql_user: | ||
db: "{{ postgres_db_name }}" | ||
name: "{{ postgres_db_username }}" | ||
password: "{{ postgres_db_password }}" | ||
expires: infinity | ||
role_attr_flags: NOSUPERUSER | ||
no_log: true | ||
tags: | ||
- molecule-idempotence-notest | ||
|
||
- name: Grant db privileges to user | ||
community.postgresql.postgresql_privs: | ||
db: "{{ postgres_db_name }}" | ||
privs: ALL | ||
type: schema | ||
objs: public | ||
role: "{{ postgres_db_username }}" | ||
tags: | ||
- molecule-idempotence-notest |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.