Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to allow downgrades with apt Ansible module?

Tags:

ansible

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
like image 815
Pablo Burgos Avatar asked May 27 '19 21:05

Pablo Burgos


1 Answers

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
like image 54
Earl Ruby Avatar answered Oct 06 '22 12:10

Earl Ruby