0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ansible: Dockerインストール時にダウングレードを許可する

Posted at

年末にAnsible勉強中です。
AnsibleでDockerをインストールするときにターゲットバージョンより、新しいバージョンがインストールされていた時の対処方法を備忘録として残します。
aptモジュールを使った他のパッケージのインストール時も同様の対処でいけるはず。

結論

  • forceにtrueを設定
  • dpkg_optionsにforce-downgradeを設定
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

実行環境

  • vagrant
    • ubntu18.04
      • box-image:ubuntu/bionic64
      • 20201125.0.0
  • ansible:2.9.16

実行結果(失敗)

最初にオプションが不足したまま、実行して、以下のようなエラーが出力され、調査しました。

ansible実行結果
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."]}

調査不足

ダウングレードするより、ターゲットバージョンと一致しない場合はアンインストールすべき?

参考

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?