---
- name: Install Postgresql dependencies
  apt: pkg={{ item }} state=installed update-cache=yes
  with_items:
    - libpq-dev

- name: Install Postgresql server and client
  apt: pkg={{ item }} state=installed update-cache=yes
  register: postgresql_install
  with_items:
    - postgresql-{{ postgresql.version}}
    - postgresql-{{ postgresql.version }}-postgis-2.1
    - postgresql-contrib
    - postgresql-server-dev-{{ postgresql.version }}
  tags:
    - packages

- name: Install PostgreSQL hba config file
  template: src=pg_hba.conf
            dest=/etc/postgresql/{{ postgresql.version }}/main/pg_hba.conf
            owner={{ postgresql.user }} group={{ postgresql.group }}

- name: Install PostgreSQL config file
  template: src=postgresql.conf
            dest=/etc/postgresql/{{ postgresql.version }}/main/postgresql.conf
            owner={{ postgresql.user }} group={{ postgresql.group }}
  notify:
    - restart postgresql
  tags:
    - configuration

- name: Create wcmc postgres role for web server
  command: echo "CREATE USER {{ postgresql_user.username }} WITH SUPERUSER LOGIN PASSWORD '{{ postgresql_user.password }}'" | psql -U postgres
  ignore_errors: True

---
- name: Install Postgresql dependencies
  apt: pkg={{ item }} state=installed update-cache=yes
  with_items:
    - libpq-dev

- name: Install Postgresql server and client
  apt: pkg={{ item }} state=installed update-cache=yes
  register: postgresql_install
  with_items:
    - postgresql-{{ postgresql.version}}
    - postgresql-{{ postgresql.version }}-postgis-2.1
    - postgresql-contrib
    - postgresql-server-dev-{{ postgresql.version }}
  tags:
    - packages

- name: Install PostgreSQL hba config file
  template: src=pg_hba.conf
            dest=/etc/postgresql/{{ postgresql.version }}/main/pg_hba.conf
            owner={{ postgresql.user }} group={{ postgresql.group }}

- name: Install PostgreSQL config file
  template: src=postgresql.conf
            dest=/etc/postgresql/{{ postgresql.version }}/main/postgresql.conf
            owner={{ postgresql.user }} group={{ postgresql.group }}
  notify:
    - restart postgresql
  tags:
    - configuration

- name: Create wcmc postgres role for web server
  command: psql -U postgres -c "CREATE USER {{ postgresql_user.username }} WITH SUPERUSER LOGIN PASSWORD '{{ postgresql_user.password }}'"

Use correct psql flag for running commands non-interactively
Use correct psql flag for running commands non-interactively
