postgres.sls 1.19 KB
Newer Older
Bach Dániel committed
1
{% if grains['os_family'] == 'RedHat' %}
2 3 4
postgresql-server:
  pkg.installed

Bach Dániel committed
5 6 7 8
postgresql_initdb:
  cmd.run:
    - cwd: /
    - user: root
Bach Dániel committed
9
    - name: postgresql-setup initdb
Bach Dániel committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23
    - unless: test -f /var/lib/pgsql/data/postgresql.conf
    - env:
      LC_ALL: C.UTF-8
  file.managed:
    - name: /var/lib/pgsql/data/pg_hba.conf
    - template: jinja
    - source: salt://manager/files/pg_hba.conf
    - user: postgres
    - group: postgres
    - mode: 600
    - require:
       - cmd: postgresql_initdb
{% endif %}

Guba Sándor committed
24 25 26
postgres_service:
  service.running:
    - name: postgresql
Bach Dániel committed
27 28 29 30 31
    - enable: True
    {% if grains['os_family'] == 'RedHat' %}
    - require:
      - file: postgresql_initdb
    {% endif %}
Guba Sándor committed
32 33 34 35 36

dbuser:
  postgres_user.present:
    - name: {{ pillar['database']['user'] }}
    - password: {{ pillar['database']['password'] }}
Bach Dániel committed
37
    - user: postgres
Guba Sándor committed
38 39 40 41 42 43 44 45 46 47 48
    - require:
      - service: postgresql

database:
  postgres_database.present:
    - name: {{ pillar['database']['name'] }}
    - encoding: UTF8
    - lc_ctype: en_US.UTF8
    - lc_collate: en_US.UTF8
    - template: template0
    - owner: {{ pillar['database']['user'] }}
Bach Dániel committed
49
    - user: postgres
Guba Sándor committed
50 51 52
    - require:
      - service: postgresql
      - postgres_user: dbuser