# PostgreSQL 9.5 or Higher installation on Ubuntu 14.04 LTS

**URL:** <https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [January 27, 2017, 4:53pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579 "2017-01-27T16:53:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shyam\_Yenna](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shyam\_Yenna](https://forum.ansible.com/u/Shyam_Yenna)\
**Post date:** [January 27, 2017, 4:53pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/1 "2017-01-27T16:53:52Z")

</div>

I am trying to install PostgreSQL 9.5 version on Ubuntu 14.04 LTS using ansible 2.2.1 version playbook tasks. According to my workflow design add apt key, add apt repository and later install postgresql packages. But dependencies packages are broken due to version difference. How to overcome this issue i am unable to find below packages in default os packages. I appreciate your help.

 ![](https://us1.discourse-cdn.com/ansible/original/2X/e/e4c67bf8e1cebee98cb5e9bf734bd9e6db58f36e.png)

Thanks  
Shyam

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 27, 2017, 7:22pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/2 "2017-01-27T19:22:13Z")

</div>

Please show the exact playbook and the actual error messages.

Did you add the update\_cache option to the apt installation task?

Johannes

---

<div class="post-metadata">

**Author:** ![Shyam\_Yenna](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shyam\_Yenna](https://forum.ansible.com/u/Shyam_Yenna)\
**Post date:** [January 29, 2017, 3:05pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/3 "2017-01-29T15:05:23Z")

</div>

Johannes,

Thanks for getting back to me quickly. Please find my playbook steps

- name: PostgreSQL | Add PostgreSQL repository apt-key  
apt\_key:  
id: “{{ postgresql\_apt\_key\_id }}”  
url: “{{ postgresql\_apt\_key\_url }}”  
state: present  
register: key\_result

- name: PostgreSQL | Add PostgreSQL repository  
apt\_repository:  
repo: “{{ postgresql\_apt\_repository }}”  
state: present  
update\_cache: true  
filename: “postgres”  
when: key\_result.changed  
register: repoadd

- name: PostgreSQL | Add PostgreSQL repository preferences  
template:  
src: “pgdg.pref.j2”  
dest: “/etc/apt/preferences.d/apt\_postgresql\_org\_pub\_repos\_apt.pref”  
backup: yes

- name: PostgreSQL | Make sure the dependencies are installed  
apt:  
name: “{{ item }}”  
state: present  
update\_cache: true  
with\_items: [‘python-psycopg2’, ‘python-pycurl’, ‘locales’, ‘sysstat’, ‘libpq5’]

- name: PostgreSQL | Install PostgreSQL  
apt:  
name: “{{ item }}”  
state: present  
update\_cache: true  
environment: “{{ postgresql\_env }}”  
when: repoadd.changed  
with\_items:

- “postgresql-common”

- “postgresql-{{ postgresql\_version }}”

- “postgresql-client-{{ postgresql\_version }}”

- “postgresql-contrib-{{ postgresql\_version }}”

Thanks  
Shyam

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [January 29, 2017, 4:19pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/4 "2017-01-29T16:19:18Z")

</div>

> - name: PostgreSQL | Make sure the dependencies are installed  
> &nbsp;&nbsp;apt:  
> &nbsp;&nbsp;&nbsp;&nbsp;name: "{{ item }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;state: present  
> &nbsp;&nbsp;&nbsp;&nbsp;update\_cache: true  
> &nbsp;&nbsp;with\_items: ['python-psycopg2', 'python-pycurl', 'locales', 'sysstat',  
> 'libpq5']

Does this step return an error?

> - name: PostgreSQL | Install PostgreSQL  
> &nbsp;&nbsp;apt:  
> &nbsp;&nbsp;&nbsp;&nbsp;name: "{{ item }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;state: present  
> &nbsp;&nbsp;&nbsp;&nbsp;update\_cache: true  
> &nbsp;&nbsp;environment: "{{ postgresql\_env }}"  
> &nbsp;&nbsp;when: repoadd.changed  
> &nbsp;&nbsp;with\_items:  
> &nbsp;&nbsp;&nbsp;&nbsp;- "postgresql-common"  
> &nbsp;&nbsp;&nbsp;&nbsp;- "postgresql-{{ postgresql\_version }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;- "postgresql-client-{{ postgresql\_version }}"  
> &nbsp;&nbsp;&nbsp;&nbsp;- "postgresql-contrib-{{ postgresql\_version }}"

What is the actual error message?

From your playbook it could be lots of things, from missing variables  
to whatever. Hard to say.

Johannes

---

<div class="post-metadata">

**Author:** ![Shyam\_Yenna](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shyam\_Yenna](https://forum.ansible.com/u/Shyam_Yenna)\
**Post date:** [January 30, 2017, 3:54pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/5 "2017-01-30T15:54:57Z")

</div>

I posted exact error message in my first mail for below step.

Does this step return an error?

> - name: PostgreSQL | Install PostgreSQL  
> apt:  
> name: “{{ item }}”  
> state: present  
> update\_cache: true  
> environment: “{{ postgresql\_env }}”  
> when: repoadd.changed  
> with\_items:
> - “postgresql-common”
> - “postgresql-{{ postgresql\_version }}”
> - “postgresql-client-{{ postgresql\_version }}”
> - “postgresql-contrib-{{ postgresql\_version }}”

![](https://groups.google.com/group/ansible-project/attach/5b7c416ce16fd/Auto%20Generated%20Inline%20Image%201?part=0.1&authuser=0)

Unable to install package as depends are not met. Technically i have added repository of postgresql 9.5, still i get dependencies not match with exact version number to proceed on installation.

Thanks  
Shyam

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [January 30, 2017, 6:51pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/6 "2017-01-30T18:51:56Z")

</div>

The error looks a lot like apt-get is unable to find the packages  
you want. Until you fix that I don’t think there’s much Ansible can  
do, it’s just asking apt-get to install the packages you specify.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 30, 2017, 9:45pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/7 "2017-01-30T21:45:53Z")

</div>

Correct.  
Something is off with your custom apt-get repositories. Fix that manually first, but without adding potentially complicating factors like Ansible to the mix. Once you’ve established your steps actually work, only then comes the time to add Ansible.

Depending on your environment it might be less hassle to apt-get dist-upgrade to Ubuntu 16.04 which already has PG 9.5.

Dick

---

<div class="post-metadata">

**Author:** ![Shyam\_Yenna](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shyam\_Yenna](https://forum.ansible.com/u/Shyam_Yenna)\
**Post date:** [January 30, 2017, 10:31pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/8 "2017-01-30T22:31:00Z")

</div>

Thanks for all replies…

I understood clearly error.

My point here is to get a workaround solution to install postgresql 9.5 repository on ubuntu 14.04 LTS. As PostgreSQL repository package is not providing depend packages in repository and i am unsuccessful in installing packages like postgresql-common \>=158 & libpq5 \>=9.5.5 on Ubuntu 14.04 LTS.

I appreciate for all your valuable feedbacks

Thanks  
Shyam

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [January 31, 2017, 8:55am UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/9 "2017-01-31T08:55:42Z")

</div>

I just tried your playbook on an existing Ubuntu 14.04 host. You  
didn't supply any vars so I made an estimate guess:

&nbsp;&nbsp;vars:  
&nbsp;&nbsp;&nbsp;&nbsp;postgresql\_apt\_key\_id: ACCC4CF8  
&nbsp;&nbsp;&nbsp;&nbsp;postgresql\_apt\_key\_url: [https://www.postgresql.org/media/keys/ACCC4CF8.asc](https://www.postgresql.org/media/keys/ACCC4CF8.asc)  
&nbsp;&nbsp;&nbsp;&nbsp;postgresql\_apt\_repository: deb  
[http://apt.postgresql.org/pub/repos/apt/](http://apt.postgresql.org/pub/repos/apt/) trusty-pgdg main  
&nbsp;&nbsp;&nbsp;&nbsp;postgresql\_version: "9.5"

The only thing I had no clue about was the template tasks with  
"pgdg.pref.j2" so I left that out.  
After remove a few 'when' statements it worked a treat, all  
dependencies got installed without a problem.

You might need to revise the conditionals in your playbook - I think  
there are a bit too many of them.

Dick

---

<div class="post-metadata">

**Author:** ![Shyam\_Yenna](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Shyam\_Yenna](https://forum.ansible.com/u/Shyam_Yenna)\
**Post date:** [January 31, 2017, 7:16pm UTC](https://forum.ansible.com/t/postgresql-9-5-or-higher-installation-on-ubuntu-14-04-lts/23579/10 "2017-01-31T19:16:44Z")

</div>

Thanks Dick…

I really appreciate all your help.

–shyam
