๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible-playbooks/roles/postgres/tasks/run_query.yml

44 lines
1.1 KiB

2 years ago
- name: fail if query is not an object
fail:
msg: query must be an object
when: query is not mapping
- name: fail if query parameters are incorrect
fail:
msg: some query parameters are incorrect
when: query.text is not string
- name: execute query
community.postgresql.postgresql_query:
db: "{{ query.database | d(omit) }}"
query: "{{ query.text }}"
positional_args: "{{ query.positional_args | d(omit) }}"
register: db_result
changed_when: false
- name: set query result
set_fact:
query_result: "{{ db_result.query_result | d({}) }}"
- block:
- name: grant privileges to all tables
community.postgresql.postgresql_privs:
database: "{{ query.database }}"
privs: ALL
type: table
objs: ALL_IN_SCHEMA
role: "{{ query.user }}"
- name: grant privileges to all sequences
community.postgresql.postgresql_privs:
database: "{{ query.database }}"
privs: ALL
type: sequence
objs: ALL_IN_SCHEMA
role: "{{ query.user }}"
when: query.refresh_privs | d(false) == true