135 lines
4.3 KiB
YAML
135 lines
4.3 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/
|
|
#
|
|
###########################################################################
|
|
# tasks file for docker
|
|
|
|
############################################################
|
|
- name: Ensure old docker packages are removed (Debian based distros)
|
|
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
|
|
- lsb-release
|
|
#- 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
|
|
| gpg --dearmor -o /etc/apt/keyrings/docker.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: >
|
|
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
|
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
#/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
|
|
- docker-buildx-plugin
|
|
- docker-compose-plugin
|
|
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
|
|
|
|
############################################################
|
|
- name: Create symlink for docker-compose
|
|
file:
|
|
src: /usr/libexec/docker/cli-plugins/docker-compose
|
|
dest: /usr/local/bin/docker-compose
|
|
owner: root
|
|
group: root
|
|
state: link
|
|
|
|
# EOF
|