Ansible:没有可用的与“docker-ce”匹配的包

Ansible:没有可用的与“docker-ce”匹配的包

我有 ansible 剧本,假设在由 Ampere (arm) 提供支持的 Oracle Cloud 上安装 Docker,该云运行运行 ARM 版本的 Ubuntu。剧本如下:

- name: Set sudo
  set_fact:
    ansible_become: yes
    ansible_become_method: sudo

- name: Docker installation - installing prerequisites
  ansible.builtin.apt:
    name:
      - apt-transport-https
      - ca-certificates
      - curl
      - gnupg-agent
      - software-properties-common
    update_cache: yes

- name: Docker installation - Adding apt-key
  ansible.builtin.apt_key:
    url: https://download.docker.com/linux/ubuntu/gpg

- name: Docker installation - Adding docker repo
  ansible.builtin.apt_repository:
    repo: deb [arch=armhf] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
    state: present
    update_cache: yes

- name: Update cache
  ansible.builtin.apt:
    update_cache: yes

- name: Docker installation - Installing Docker
  ansible.builtin.apt:
    name:
      - docker-ce
      - docker-ce-cli
      - containerd.io
    update_cache: yes

我在 stackoverflow 上发布了这个问题,但建议移至此处并添加一些信息。其中一个信息是“ansible_lsb.codename 的值是多少。我添加了另一个小任务,以便 ansible 打印该变量的值。该部分直接放置在任务 tkat 导致问题之前

- name: Print
  debug:
    msg: "{{ ansible_lsb.codename }}"

The output is the following

ok: [XXX.XXX.XXX.XXX] => {
    "msg": "mantic"
}

根据建议,我还检查了armhf构建的可用性,但据我所知,此类构建是可用的

在此输入图像描述

问题是,由于某种原因,最后一个任务“Docker 安装 - 安装 Docker”抛出错误

fatal: [XXX.XXX.XXX.XXX]: FAILED! => {"changed": false, "msg": "No package matching 'docker-ce' is available"}

任何帮助表示赞赏。

答案1

今天我也遇到了同样的问题!但我的策略在一年前表现得非常完美。有线的东西...我尝试手动将存储库添加到我的主机中,一切正常。但不是用ansible...

更新:我可以用这个配置安装它

- name: Install required system packages
  apt:
    name: "{{ packages }}"
    state: latest
    update_cache: yes
  vars:
    packages:
      - apt-transport-https
      - ca-certificates
      - curl
      - software-properties-common

- name: Add Docker’s official GPG key
  apt_key:
    url: https://download.docker.com/linux/ubuntu/gpg
    state: present

- name: Add Docker repository
  apt_repository:
    repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
    state: present

- name: Install Docker CE
  apt:
    name: docker-ce
    state: latest
    update_cache: yes

- name: Install Docker Compose
  get_url:
    url: https://github.com/docker/compose/releases/download/1.29.2/docker-compose-{{ ansible_system }}-{{ ansible_userspace_architecture }}
    dest: /usr/local/bin/docker-compose
    mode: 'u+x,g+x'

- name: Verify Docker Compose installation
  command: docker-compose --version
  register: docker_compose_version
- debug:
    var: docker_compose_version.stdout_lines

相关内容