我有一本Ansible Playbook,用于部署特定版本的docker。我希望apt模块在目标计算机安装了更高版本时允许降级。我浏览了文档,但找不到合适的方法。 Yaml文件中的行如下:
- name : "Install specific docker ce"
become : true
apt :
name : docker-ce=5:18.09.1~3-0~ubuntu-bionic
state : present
答案 0 :(得分:0)
对于Ubuntu上的Docker CE,有两个软件包,docker-ce
和docker-ce-cli
。您可以查看当前安装了哪些版本:
$ apt list --installed | grep docker
docker-ce/xenial,now 5:18.09.7~3-0~ubuntu-xenial amd64 [installed,upgradable to: 5:19.03.1~3-0~ubuntu-xenial]
docker-ce-cli/xenial,now 5:18.09.7~3-0~ubuntu-xenial amd64 [installed,upgradable to: 5:19.03.1~3-0~ubuntu-xenial]
您需要为两个软件包强制使用相同的版本。例如在Ubuntu Xenial上:
- name: Install docker-ce
apt:
state: present
force: True
name:
- "docker-ce=5:18.09.7~3-0~ubuntu-xenial"
- "docker-ce-cli=5:18.09.7~3-0~ubuntu-xenial"
notify:
- Restart docker
when: ansible_os_family == "Debian" and ansible_distribution_version == "16.04"
# Equivalent to `systemctl daemon-reload && systemctl restart docker`
- name: Restart docker
systemd:
name: docker
daemon_reload: True
state: restarted