如何在Ansible中定义要安装的软件包版本

时间:2014-09-22 13:14:46

标签: postgresql postgresql-9.1 ansible ansible-playbook

我正在使用Ansible,我想在main.yml任务中定义包的版本。我正在尝试安装postgresql-9.1版本:

---
- 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

但我收到了这个错误:

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 

然后,如何声明要安装的软件包版本?

1 个答案:

答案 0 :(得分:0)

您正在使用apt模块来指定版本。这也会在apt-get install postgresql-9.1的命令行失败。您还没有显示sources.list中的内容,但他是一种方法:

- 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