- name: Install required Python modules
  pip: name=psycopg2

- name: Install packages
  apt: name={{ item }}
  with_items:
    - libpq-dev
    - postgresql
    - postgresql-contrib

- name: Create postgresql user
  postgresql_user: name={{ postgresql_db_user }} password={{ postgresql_db_password }} role_attr_flags=CREATEDB

- name: Create postgresql database
  postgresql_db: name={{ postgresql_db_name }} owner={{ postgresql_db_user }}

- name: Create config/database.yml
  template: src=database.yml.j2 dest={{ app_config_path }}/database.yml owner={{ user_name }} mode=0600 backup=yes

- name: Install required Python modules
  pip: name=psycopg2

- name: Install packages
  apt: name={{ item }}
  with_items:
    - libpq-dev
    - postgresql
    - postgresql-contrib

- name: Create postgresql user
  postgresql_user: name={{ postgresql_db_user }} password={{ postgresql_db_password }} role_attr_flags=CREATEDB
  sudo_user: postgres

- name: Create postgresql database
  postgresql_db: name={{ postgresql_db_name }} owner={{ postgresql_db_user }}
  sudo_user: postgres

- name: Create config/database.yml
  template: src=database.yml.j2 dest={{ app_config_path }}/database.yml owner={{ user_name }} mode=0600 backup=yes

Use postgres user to create new role and DB
Use postgres user to create new role and DB
