  - name: install postgresql
    action: yum name={{ item }} state=latest
    notify:
      - restart postgresql
    with_items:
      - postgresql-server
      - postgresql-devel
      - python-psycopg2

  - name: initdb for postgresql
    command: /etc/init.d/postgresql initdb creates=/var/lib/pgsql/data/postgresql.conf

  - name: configure pg_hba.conf
    action: lineinfile
      dest=/var/lib/pgsql/data/pg_hba.conf
      state=present
      "line={{ item }}"
      "insertbefore=^# TYPE"
    with_items:
      - "local rattic rattic password"
      - "host rattic rattic 127.0.0.0/8 password"
      - "host rattic rattic ::1/128 password"
    notify:
      - restart postgresql

  - name: set PostgreSQL to start
    action: service name=postgresql state=started enabled=yes

  - name: create PostgreSQL user
    action: postgresql_user name={{db_user}} password={{db_passwd}} encrypted=false state=present
    sudo_user: postgres

  - name: create PostgreSQL database
    action: postgresql_db name={{db_name}} owner={{db_user}} state=present
    sudo_user: postgres
    notify:
      - create initial user

  - name: Setup virtualenv (pgsql)
    pip: requirements=/opt/apps/RatticWeb/requirements-pgsql.txt virtualenv=/opt/apps/RatticWeb.venv
    notify:
      - restart httpd
