12

I have an Ansible Playbook to deploy a specific version of docker. I want apt module to allow for downgrades when the target machine have a higher version installed. I browsed the documentation but couldn't find a suitable way to do it. The Yaml file have lines like:

- name : "Install specific docker ce"
  become : true 
  apt : 
    name : docker-ce=5:18.09.1~3-0~ubuntu-bionic
    state : present
6
  • 1
    Is that playbook snippet producing an error or is it just not downgrading your docker-ce package?
    – mdaniel
    May 28, 2019 at 3:04
  • 1
    I'm having an error, task failed to complete. The error is : "stderr": "E: Packages were downgraded and -y was used without --allow-downgrades.\n", May 28, 2019 at 3:08
  • 3
    According to the fine manual, --force-downgrade is legal, and thus apt: dpkg_options: ["force-downgrade"] should allow it to downgrade; can you try that?
    – mdaniel
    May 28, 2019 at 5:49
  • 4
    try it with force: yes option.
    – AHT
    May 29, 2019 at 3:55
  • 4
    Damn, that's my fault: as you can see from the presence of --['force-downgrade'] they don't want a list of string they just split on "," so it should have been dpkg_options: force-downgrade; I'm sorry for not catching that
    – mdaniel
    May 29, 2019 at 4:01

2 Answers 2

1

For Docker CE on Ubuntu there are two packages, docker-ce and docker-ce-cli. You can see which versions are currently installed with:

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

You need to force the same version for both packages. e.g. on Ubuntu Xenial:

main.yml

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

handler.yml

# Equivalent to `systemctl daemon-reload && systemctl restart docker`
- name: Restart docker
  systemd:
    name: docker
    daemon_reload: True
    state: restarted
0

allow-downgrade parameter can be used with apt module. You can find the documentation here. However note that using this option could end up with a set of packages that does not match the complete list of specified packages to install.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.