139 lines
4.5 KiB
YAML
139 lines
4.5 KiB
YAML
---
|
|
###########################################################################
|
|
#
|
|
# This role is based on the steps presented at;
|
|
# - https://docs.docker.com/engine/install/ubuntu/
|
|
# - https://docs.docker.com/engine/install/debian/
|
|
# - https://wiki.alpinelinux.org/wiki/Docker
|
|
#
|
|
###########################################################################
|
|
# tasks file for docker
|
|
|
|
############################################################
|
|
- name: Ensure old docker packages are removed (Debian based repos)
|
|
apt:
|
|
name:
|
|
- docker
|
|
- docker-engine
|
|
- docker.io
|
|
- containerd
|
|
- runc
|
|
state: absent
|
|
when: ansible_os_family == "Debian"
|
|
|
|
############################################################
|
|
- name: Ensure required supporting packages are installed (Ubuntu)
|
|
apt:
|
|
name:
|
|
- apt-transport-https
|
|
- ca-certificates
|
|
- curl
|
|
- gnupg-agent
|
|
- software-properties-common
|
|
state: present
|
|
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS" or ansible_distribution == "Linux Mint"
|
|
|
|
############################################################
|
|
- name: Ensure required supporting packages are installed (Debian)
|
|
apt:
|
|
name:
|
|
- ca-certificates
|
|
- curl
|
|
- gnupg
|
|
- lsb-release
|
|
state: present
|
|
when: ansible_distribution == "Debian"
|
|
|
|
############################################################
|
|
- name: Retrieve docker's official GPG key (Ubuntu)
|
|
shell:
|
|
cmd: >
|
|
/usr/bin/curl -fsSL
|
|
https://download.docker.com/linux/ubuntu/gpg
|
|
| /usr/bin/apt-key add -
|
|
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS" or ansible_distribution == "Linux Mint"
|
|
|
|
############################################################
|
|
- name: Remove keyring file (if exists) (Debian)
|
|
file:
|
|
path: /usr/share/keyrings/docker-archive-keyring.gpg
|
|
state: absent
|
|
when: ansible_distribution == "Debian"
|
|
|
|
############################################################
|
|
- name: Retrieve docker's official GPG key (Debian)
|
|
shell:
|
|
cmd: >
|
|
/usr/bin/curl -fsSL
|
|
https://download.docker.com/linux/debian/gpg
|
|
| gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
|
|
when: ansible_distribution == "Debian"
|
|
|
|
############################################################
|
|
- name: Add the stable docker repository (Ubuntu)
|
|
shell:
|
|
cmd: >
|
|
/usr/bin/add-apt-repository
|
|
"deb https://download.docker.com/linux/ubuntu
|
|
{{ ansible_distribution_release }}
|
|
stable"
|
|
when: ansible_distribution == "Ubuntu" or ansible_distribution == "Pop!_OS" or ansible_distribution == "Linux Mint"
|
|
|
|
############################################################
|
|
- name: Add the stable docker repository (Debian)
|
|
shell:
|
|
cmd: >
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
|
|
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
when: ansible_distribution == "Debian"
|
|
|
|
############################################################
|
|
- name: Update package cache (Ubuntu/Debian)
|
|
apt:
|
|
update-cache: true
|
|
when: ansible_os_family == "Debian"
|
|
|
|
############################################################
|
|
- name: Install docker packages (Ubuntu/Debian)
|
|
apt:
|
|
name:
|
|
- docker-ce
|
|
- docker-ce-cli
|
|
- containerd.io
|
|
state: present
|
|
when: ansible_os_family == "Debian"
|
|
|
|
############################################################
|
|
- name: Add user to docker group
|
|
user:
|
|
name: "{{ username }}"
|
|
groups: docker
|
|
append: true
|
|
|
|
############################################################
|
|
- name: Enable docker daemon
|
|
systemd:
|
|
name: docker
|
|
enabled: true
|
|
|
|
############################################################
|
|
# using the pip3 command rather than the pip ansible module
|
|
# because ansible can get in a weird state depending on the
|
|
# python version used on the target host
|
|
- name: Install docker python package
|
|
shell:
|
|
cmd: pip3 install docker
|
|
|
|
############################################################
|
|
- name: Install docker-compose
|
|
shell:
|
|
cmd: curl -L "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
|
|
############################################################
|
|
- name: Set permissions on /usr/local/bin/docker-compose
|
|
file:
|
|
path: /usr/local/bin/docker-compose
|
|
mode: "0755"
|
|
|
|
# EOF
|