---
- name: Add PostgreSQL signing key
  apt_key:
    url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
    state: present

- name: Add PostgreSQL repository
  apt_repository:
    repo: deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main
    state: present
    update_cache: yes

- name: Install PostgreSQL
  apt:
    pkg: "{{ item }}"
    state: present
    update_cache: yes
  with_items:
   - postgresql-server-dev-9.4
   - postgresql-9.4
---
- name: Add PostgreSQL signing key
  apt_key:
    url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
    state: present

- name: Add PostgreSQL repository
  apt_repository:
    repo: deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main
    state: present
    update_cache: yes

- name: Install PostgreSQL
  apt:
    pkg: "{{ item }}"
    state: present
    update_cache: yes
  with_items:
   - postgresql-server-dev-9.4
   - postgresql-9.4
   - python-psycopg2

Install psycopg2 as well when installing PostgreSQL
Install psycopg2 as well when installing PostgreSQL
