commit f08cc8b54157160740b5cf0b97337bf787b5b910 Author: Patrick Neff Date: Fri Jul 8 21:49:28 2022 +0200 Initial commit diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..237ad63 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "*.yml": "ansible" + } +} diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..5734952 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,3 @@ +psql_users: [] +psql_databases: [] +psql_privileges: [] diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..113880c --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,4 @@ +galaxy_info: + role_name: postgeresql + +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..7a8dac0 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,44 @@ +- name: Install packages. + tags: postgresql + become: true + ansible.builtin.package: + name: + - postgresql + - postgresql-client + - python3-psycopg2 + +- name: Create databases. + become: true + become_user: postgres + tags: postgresql + community.postgresql.postgresql_db: + encoding: "{{ item.encoding | default('utf8') }}" + target: "{{ item.target | default(omit) }}" + name: "{{ item.name }}" + state: "{{ item.state | default('present') }}" + with_items: "{{ psql_databases }}" + +- name: Create database users. + become: true + become_user: postgres + tags: postgresql + community.postgresql.postgresql_user: + name: "{{ item.name }}" + host: "{{ item.host | default(omit) }}" + password: "{{ item.password | default(omit) }}" + state: "{{ item.state | default('present') }}" + with_items: "{{ psql_users }}" + +- name: Create database privileges + become: true + become_user: postgres + tags: postgresql + community.postgresql.postgresql_privs: + db: "{{ item.db | default(omit) }}" + privs: "{{ item.privs | default('SELECT,INSERT,UPDATE') }}" + objs: "{{ item.objs }}" + type: "{{ item.type | default(omit) }}" + database: "{{ item.database | default(omit) }}" + roles: "{{ item.roles }}" + grant_option: "{{ item.grant_option | default('yes') }}" + with_items: "{{ psql_privileges }}" \ No newline at end of file