1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#......................PostgreSQL Default User (roles)....................

# merge postgres users pillars, postgres_app wins collision.
{% set users = salt['pillar.get']('postgres:users', {}).copy() %}
{% users.update(salt['pillar.get']('postgres_app:users', {})) %}

# iterate over all optionally defined users in pillar and create them.
{% for user, password in users.items() %}
{% set groups = salt['pillar.get']('postgres:user_group_map:{}'.format(user), []) %}
postgres-{{ user }}:
  postgres_user.present:
    - name: {{ user }}
    - password: {{ password }}
    - runas: postgres
    - user: postgres
    - encrypted: True
    - groups: {{ ','.join(groups) }}
    - require:
      - service.running: postgresql
      {% for group in groups %}
      - postgres_group.present: {{ group }}
      {% endfor %}
{% endfor %}