-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
docker.yml
executable file
·84 lines (73 loc) · 2.4 KB
/
docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
- name: Install Docker engine
hosts: all
become: true
vars_prompt:
- name: 'user'
prompt: 'Enter the name of the user to add to the docker group:'
private: no
tasks:
- name: Gather the package facts
package_facts:
manager: auto
- name: Set distribution variable
set_fact:
distribution: "{{ ansible_facts['distribution'] | lower }}"
- name: Uninstall old versions
apt:
name:
- docker
- docker-engine
- docker.io
- containerd
- runc
state: absent
autoremove: true
update_cache: true
when: distribution == 'debian' or distribution == 'ubuntu'
- name: Remove docker repository file
file:
path: /etc/apt/sources.list.d/docker.list
state: absent
when: distribution == 'debian' or distribution == 'ubuntu'
- name: Install dependencies (Debian/Ubuntu)
apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
state: present
update_cache: true
when: distribution == 'debian' or distribution == 'ubuntu'
- name: Add Docker GPG apt Key (Debian/Ubuntu)
apt_key:
url: https://download.docker.com/linux/{{ distribution }}/gpg
state: present
when: distribution == 'debian' or distribution == 'ubuntu'
- name: Add Docker Repository (Debian/Ubuntu)
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/{{ distribution }} {{ ansible_facts['distribution_version'] }} stable"
state: present
when: distribution == 'debian' or distribution == 'ubuntu'
- name: Install docker engine, containerd, and Docker Compose (Debian/Ubuntu)
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose
state: present
update_cache: true
when: distribution == 'debian' or distribution == 'ubuntu'
# Add equivalent tasks for CentOS, Fedora, Raspbian etc., by checking distribution and using respective package managers (yum/dnf) and commands.
- name: Test docker
command: docker info
- name: Test docker compose
command: docker compose version
- name: Add remote "{{ user }}" user to "docker" group
user:
name: '{{ user }}'
groups: docker
append: yes
tags:
- docker