Ansible 安装失败(docker-latest docker docker-python python-docker-py)

Ansible 安装失败(docker-latest docker docker-python python-docker-py)

我正在尝试运行以下剧本

.
.
.
  tasks:
    - name: Install python and build dependencies
      yum: pkg={{ item }} state=installed
      with_items:
         - docker-latest
         - docker
         - docker-python
         - python-docker-py
 .
 .
 .

但这是我得到的:

failed: [myVM] (item=['docker-latest', 'docker', 'docker-python', 'python-docker-py'])
               => {"changed": false,
                   "failed": true,
                   "item": ["docker-latest",
                            "docker",
                            "docker-python",
                            "python-docker-py"],
                   "msg": "No package matching 'docker-latest' found available, installed or updated",
                   "rc": 126,
                   "results": ["No package matching 'docker-latest' found available, installed or updated"]
                   }

我的主机操作系统是 CentOS Linux 版本 7.9.2009。

答案1

回答

根据该docker-latest包裹不属于列表的一部分官方的码头工人文档

该过程表明您需要安装以下软件包:

yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

所以在你的情况下安装码头工人堆栈与安西布尔(使用新语法替换您提供的循环):

# ...
- name: Install Docker packages
  ansible.builtin.yum:
    name:
      - docker-ce
      - docker-ce-cli
      - containerd.io
      - docker-buildx-plugin
      - docker-compose-plugin
    state: latest
# ...

您可以通过将所需的任何其他包添加到列表中来添加它们。

安装 Docker 的 Ansible 手册

这是我为安装 Docker 制作的一个简单的剧本。请将其视为适应的基础,而不是准备运行的脚本......

---
- name: Install Docker stack on CentOS 7
  hosts: <yourTarget(s)>

  tasks:
  - name: Upgrade all packages
    ansible.builtin.yum:
      name: "*"
      state: latest

  - name: Remove old Docker packages
    ansible.builtin.yum:
      name:
        - docker
        - docker-client
        - docker-client-latest
        - docker-common
        - docker-latest
        - docker-latest-logrotate
        - docker-logrotate
        - docker-engine
      state: absent

  - name: Enable centos-extras repository
    ansible.builtin.yum_repository:
      name: centos-extras
      state: present
      enabled: true

  - name: Set up Docker repository
    ansible.builtin.get_url:
      url: https://download.docker.com/linux/centos/docker-ce.repo
      dest: /etc/yum.repos.d/docker-ce.repo

  - name: Install Docker packages
    ansible.builtin.yum:
      name:
        - docker-ce
        - docker-ce-cli
        - containerd.io
        - docker-buildx-plugin
        - docker-compose-plugin
      state: latest

  - name: Enable and start Docker service
    ansible.builtin.service:
      name: docker
      state: restarted
      enabled: true

相关内容