No package matching 'docker-ce' is available with ansible

3

0

On ubuntu 18.04 I am running this ansible (version 2.5.1) role:

---
- name: Add Docker apt repository key.
  apt_key:
    url: "https://download.docker.com/linux/ubuntu/gpg"
    state: present

- name: gather facts
  setup:    

- name: Set the stable docker repository
  apt_repository: 
    repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable"
    state: present
    update_cache: yes    

- name: Install Docker
  apt:
    name: docker-ce
    state: present

With this playbook:

---


- hosts: localhost
  connection: local
  gather_facts: False
  become: true

  pre_tasks:
  - name: Install python for Ansible
    raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)

  tasks:  
  - name: Install list of packages
    apt: name={{item}} state=latest
    with_items:
         - nano
         - git
         - htop
         - gitg

  roles:
      - {role: 'docker', tags: 'docker'}

But I get the following error:

PLAY [localhost] *******************************************************************************************************************************

TASK [Install python for Ansible] **************************************************************************************************************
changed: [localhost]

TASK [docker : Add Docker apt repository key.] *************************************************************************************************
ok: [localhost]

TASK [docker : gather facts] *******************************************************************************************************************
ok: [localhost]

TASK [docker : Set the stable docker repository] ***********************************************************************************************
ok: [localhost]

TASK [docker : Install Docker] *****************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "No package matching 'docker-ce' is available"}
    to retry, use: --limit @/home/user/repos/ansible-vps/src/ansible_create_workstation.retry

PLAY RECAP *************************************************************************************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=1   

So for some reason the docker-ce package cannot be found, has that changed recently or is it something else I am doing wrong?

Also when I look in: /etc/apt/sources.list it does not contain a:

deb [arch=amd64] https://download.docker.com/linux/ubuntu  ...

entry.

u123

Posted 2018-05-17T20:21:39.067

Reputation: 359

Answers

5

You need to use edge instead of stable with bionic (18.04), it will be in stable in the future.

- name: Set the stable docker repository
  apt_repository: 
    repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} edge"
    state: present
    update_cache: yes    

frbayart

Posted 2018-05-17T20:21:39.067

Reputation: 116

0

There is a matching post on StackOverflow : Ansible: no package available for docker-ce.

The accepted answer says :

Or you can use generic OS package manager module if Ansible version >= 2.0:

- name: install docker
  package:
    name: docker-ce
    state: present

A comment below says :

replace $(lsb_release -cs) with xenial (for ubuntu 16.04) from your /etc/apt/sources.list and retry

harrymc

Posted 2018-05-17T20:21:39.067

Reputation: 306 093

0

One could also check ansible-galaxy first and use a well tested ansible role like https://github.com/geerlingguy/ansible-role-docker. No need to reinvent the wheel.

030

Posted 2018-05-17T20:21:39.067

Reputation: 1 924