I am studying Ansible at the end of the year. When installing Docker with Ansible, I will leave a memorandum of what to do when a newer version than the target version is installed. You should be able to do the same when installing other packages using the apt module.
main.yml
- name: Docker | Install Docker | apt
apt:
name:
- "docker-ce={{docker_ce_version}}"
- "docker-ce-cli={{docker_ce_cli_version}}"
- "containerd.io={{containerd_io_version}}"
state: present
update_cache: yes
force: yes
dpkg_options: force-downgrade
Initially, I ran it with missing options and investigated it with an error similar to the following:
ansible execution result
fatal: [192.168.xx.xx]: FAILED! => {"cache_update_time": 1609061762, "cache_updated": true, "changed": false,
"msg": "'/usr/bin/apt-get -y -o \"Dpkg::Options::=--force-confdef\" -o \"Dpkg::Options::=--force-confold\"
install 'docker-ce=5:18.09.2~3-0~ubuntu-bionic' 'docker-ce-cli=5:18.09.2~3-0~ubuntu-bionic' 'containerd.io=1.3.7-1'
' failed: E: Packages were downgraded and -y was used without --allow-downgrades.",
"rc": 100, "stderr": "E: Packages were downgraded and -y was used without --allow-downgrades.",
"stderr_lines": ["E: Packages were downgraded and -y was used without --allow-downgrades."],
"stdout": "Reading package lists...
Building dependency tree...
Reading state information...
The following package was automatically installed and is no longer required:\n
docker-ce-rootless-extras
Use 'sudo apt autoremove' to remove it.
The following packages will be DOWNGRADED:
containerd.io docker-ce docker-ce-cli
0 upgraded, 0 newly installed, 3 downgraded, 0 to remove and 10 not upgraded.",
"stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information...",
"The following package was automatically installed and is no longer required:",
" docker-ce-rootless-extras", "Use 'sudo apt autoremove' to remove it.",
"The following packages will be DOWNGRADED:",
" containerd.io docker-ce docker-ce-cli", "0 upgraded, 0 newly installed, 3 downgraded, 0 to remove and 10 not upgraded."]}
Should I uninstall it if it doesn't match the target version rather than downgrading?
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html https://stackoverflow.com/questions/56332649/is-there-a-way-to-allow-downgrades-with-apt-ansible-module
Recommended Posts