- apt_key: url=http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc state=present
- apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ {{ansible_distribution_release}}-pgdg main 9.3' state=present
- apt: pkg={{item}} state=latest update_cache=yes
  with_items:
    - postgresql-client-9.3
    - postgresql-9.3
    - postgresql-server-dev-9.3
- name: install db prerequisites
  apt: pkg={{item}} state=latest update_cache=yes
  with_items:
    - python-psycopg2 # needed for the postgresql ansible tasks
  tags: db
- name: setup db
  action: postgresql_db name={{app_name}}
  sudo_user: postgres
  sudo: true
  tags: db
- name: setup db user
  action: postgresql_user name={{app_name}} password={{app_name}} db={{app_name}} priv=ALL role_attr_flags=SUPERUSER
  sudo_user: postgres
  sudo: true
  tags: db

- apt_key: url=http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc state=present
- apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ {{ansible_distribution_release}}-pgdg main 9.3' state=present
- apt: pkg={{item}} state=latest update_cache=yes
  with_items:
    - postgresql-client-9.3
    - postgresql-9.3
    - postgresql-server-dev-9.3
- name: install db prerequisites
  apt: pkg={{item}} state=latest update_cache=yes
  with_items:
    - python-psycopg2 # needed for the postgresql ansible tasks
  tags: db
- service: name=postgresql state=started
- name: setup db
  action: postgresql_db name={{app_name}}
  sudo_user: postgres
  sudo: true
  tags: db
- name: setup db user
  action: postgresql_user name={{app_name}} password={{app_name}} db={{app_name}} priv=ALL role_attr_flags=SUPERUSER
  sudo_user: postgres
  sudo: true
  tags: db

Make sure database server is started
Make sure database server is started
