Ubuntu – No package matching ‘docker-ce’ is available with ansible

ansibleUbuntu

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.

Best Answer

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