Robert
Robert

Reputation: 10953

How define in Ansible a version of package to install

I am using Ansible and I want to define the version of the package in main.yml task. I am trying to install postgresql-9.1 version:

---
- name: Copy source list
  copy: src=sources.list dest=/etc/apt/sources.list

- name: Update apt
  shell: apt-get update

- name: Install the version 9.1 of postgresql
  sudo: True
  apt: name=postgresql=9.1  state=present

- name: Ensure postgresql is << Started >>
  sudo: yes
  sudo_user: postgres
  service: name=postgresql state=started

But I got this error:

PLAY [database] *************************************************************** 

GATHERING FACTS *************************************************************** 
ok: [slave1]

TASK: [postgresql | Copy source list] ***************************************** 
ok: [slave1]

TASK: [postgresql | Update apt] *********************************************** 
changed: [slave1]

TASK: [postgresql | Install the version 9.1 of postgresql] ******************** 
failed: [slave1] => {"failed": true}
stderr: E: Version '9.1' for 'postgresql' was not found

stdout: Reading package lists...
Building dependency tree...
Reading state information...

msg: 'apt-get install 'postgresql=9.1' ' failed: E: Version '9.1' for 'postgresql' was not found


FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/robe/site.retry

slave1                     : ok=3    changed=1    unreachable=0    failed=1 

Then, How do I declare the package version to install?

Upvotes: 2

Views: 2815

Answers (1)

300D7309EF17
300D7309EF17

Reputation: 24613

You are using the apt module correctly to specify a version. This would also fail at the commandline with apt-get install postgresql-9.1. You haven't shown what's in your sources.list, but he's a way to do it:

- apt_key: id=ACCC4CF8 url=https://www.postgresql.org/media/keys/ACCC4CF8.asc state=present
- apt_repository: repo='deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' update_cache=yes state=present
- name: Install the version 9.1 of postgresql
  apt: name=postgresql=9.1  state=present

Upvotes: 1

Related Questions