0

I am trying to run the following playbook

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

but this what I got:

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"]
                   }

My host OS is CentOS Linux release 7.9.2009.

3
  • What is the output of yum search docker-latest ? I seems that the package is not available on the target system. Maybe you need to add the docker repositories ? docs.docker.com/engine/install/centos
    – ramius
    Commented May 3, 2023 at 11:48
  • @ramius yum search docker-latest Loaded plugins: fastestmirror, priorities Loading mirror speeds from cached hostfile Warning: No matches found for: docker-latest No matches found the same output even after adding the docker repo Commented May 3, 2023 at 12:08
  • Please edit the question to add more information from questions in the comment section Commented May 3, 2023 at 13:42

1 Answer 1

2

Answer

The docker-latest package is not part of the list according to the official Docker documentation.

The procedure indicates that you need to install the following packages:

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

So in your case to install the Docker stack with Ansible (using new syntax in replacement of the loop you provided):

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

You can add any other package you want by adding them to the list.

Ansible playbook to install Docker

Here is a simple playbook I made to install Docker. Please consider it as a base to adapt, not a ready-to-run script...

---
- 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .