Skip to content

Instantly share code, notes, and snippets.

@lutangar
Last active October 18, 2021 19:01
Show Gist options
  • Save lutangar/65bff40dc61d8c48c3eb8ab179d21d11 to your computer and use it in GitHub Desktop.
Save lutangar/65bff40dc61d8c48c3eb8ab179d21d11 to your computer and use it in GitHub Desktop.
Ansible task to setup docker-ce on ubuntu or debian
---
- name: Update the `apt` package index
apt:
update_cache: yes
- name: Install packages to allow apt to use a repository over HTTPS
package:
name: "{{ item }}"
state: latest
with_items:
- apt-transport-https
- curl
- software-properties-common
- name: Install `easy_install` to install `pip`
package:
name: python-setuptools
state: present
- name: Install `pip` to install `docker-py`
easy_install:
name: pip
state: latest
- name: Install `docker-py` for the Ansible Docker module
pip:
name: "{{ item }}"
with_items:
- docker-py
# - docker-compose
- name: Add Docker’s official GPG key
apt_key:
url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg"
state: present
- name: Register distribution *short* code name
shell: lsb_release -cs
register: lsb_release
- name: Set up the stable repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable"
state: present
- name: Update the `apt` package index
apt:
update_cache: yes
- name: Install Docker CE
package:
name: docker-ce
state: present
- name: Verify that Docker CE is installed correctly by running the hello-world image
command: docker run hello-world
register: command_result
failed_when: "'Hello from Docker!' not in command_result.stdout"
@lutangar
Copy link
Author

lutangar commented Apr 1, 2021

Sure @pareul let's try ansible_distribution instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment