---
-   name: Install PostgreSQL packages
    yum: pkg={{item}} state=installed
    sudo: yes
    with_items:
        - postgresql
        - postgresql-server
        - python-psycopg2
        - postgresql-contrib
        - postgresql-libs
        - postgresql-devel

-   name: Initiate PostgreSQL database
    action: shell /sbin/service postgresql initdb 
        creates=/var/lib/pgsql/data/postgresql.conf
    sudo: yes
    notify: 
        - restart postgresql
        - ensure database is created
        - ensure user has access to database
        - ensure user does not have unnecessary privilege

-   lineinfile: "dest=/etc/sudoers  regexp='^%vagrant' state=present line='%vagrant ALL = (postgres) NOPASSWD: ALL'"
    sudo: yes
    when: local_environment

-   meta: flush_handlers


