--- - name: Install postgre and usefull packages apt: update_cache: yes name: - acl # Don't ask me, required by postgresql_user - postgresql - postgresql-contrib - libpq-dev - python3-dev - python3-psycopg2 - libpq5 state: latest - name: Enable and start PostgreSQL systemd: name: postgresql.service state: started enabled: yes - name: Create users become: true become_user: postgres postgresql_user: name: "{{ item.name }}" encrypted: yes password: "{{ item.password }}" loop: "{{ postgres_users }}" no_log: "{{ enable_no_log | default('true') }}" - name: Create databases become: true become_user: postgres postgresql_db: name: "{{ item.name }}" encoding: UTF-8 owner: "{{ item.owner | default(omit) }}" lc_collate: "{{ item.local | default(omit) }}" lc_ctype: "{{ item.local | default(omit) }}" template: "{{ item.template | default(omit) }}" loop: "{{ databases }}" - name: Set encoding become: true become_user: postgres postgresql_query: query: "ALTER ROLE {{ item }} SET client_encoding TO 'utf8'" loop: "{{ postgres_users | map(attribute='name') }}" - name: Set encoding become: true become_user: postgres postgresql_query: query: "ALTER ROLE {{ item }} SET default_transaction_isolation TO 'read committed'" when: item.read_committed | default(false) loop: "{{ postgres_users | map(attribute='name') }}" - name: Set timezone become: true become_user: postgres postgresql_query: query: "ALTER ROLE {{ item }} SET timezone TO 'CET'" loop: "{{ postgres_users | map(attribute='name') }}"