cubicweb/postgres.sls
author Katia Saurfelt <katia.saurfelt@logilab.fr>
Fri, 05 Jun 2015 18:06:03 +0200
changeset 40 54b3058cbca9
parent 39 f4ce04853cb1
permissions -rw-r--r--
[postgres] add `lc_collate` and `lc_ctype` (closes #5438104)

{% set psql_version=pillar.get('postgresql_version', 9.1) %}

pg-server:
  pkg.installed:
    - pkgs:
      - postgresql-{{ psql_version }}
      - postgresql-contrib-{{ psql_version }}
      - postgresql-plpython-{{ psql_version }}
  {% if grains['oscodename'] == 'wheezy' %}
  file.managed:
    - name: /etc/init.d/postgresql
    - source: salt://cubicweb/postgresql_patched_init
    - require_in:
      - service: postgresql
  {% endif %}
  service.running:
    - name: postgresql

postgresql-plpython-{{ psql_version }}:
  pkg.installed

/etc/postgresql/{{ psql_version }}/main/pg_hba.conf:
  file.append:
    - text:
          - host    all             all             0.0.0.0/0            md5
    - watch_in :
      service: postgresql

{% for vhostname, vhost in pillar['cubicweb_apps'].iteritems() %}
 {% for name, config in vhost.iteritems() %}

pg-{{vhostname}}-{{name}}:
  postgres_user.present:
    - name: {{ config.get('database',{}).get('user','cubicweb') }}
    - password: {{ config.get('database',{}).get('password', 'cub1cweb') }}
    - user: postgres
    - require:
      - service: postgresql
  postgres_database.present:
    - name: {{ config.database.name }}
    - owner: {{ config.database.user }}
    - encoding: 'UTF8'
    - template: template0
    {% if config.database.get('lc_collate', False) %}
    - lc_collate: {{ config.database.lc_collate }}
    {% endif %}
    {% if config.database.get('lc_ctype', False) %}
    - lc_ctype: {{ config.database.lc_ctype }}
    {% endif %}
    - require:
      - postgres_user: pg-{{vhostname}}-{{name}}
      - service: pg-server
  postgres_extension.present:
    - name: plpythonu
  postgres_user:
    - present
    - name: {{ config.database.user }}
    - password: {{ config.database.password }}
    {% if config.database.get('superuser', False) %}
    - superuser: True
    {% endif %}
    - require:
      - service: postgresql
      - pkg: postgresql-plpython-9.1
      - postgres_database: pg-{{vhostname}}-{{name}}
 {% endfor %}
{% endfor %}