Last active
October 18, 2021 19:01
-
-
Save lutangar/65bff40dc61d8c48c3eb8ab179d21d11 to your computer and use it in GitHub Desktop.
Ansible task to setup docker-ce on ubuntu or debian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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" |
This allows it to work with --check
Thanks @Geod24 👍
Wouldn't it be better to use ansible_distribution
instead of ansibe_os_family
? At least for Ubuntu it fails for me because it tries to reach the debian repo instead of the ubuntu repo?
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
This allows it to work with
--check