-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtasks_docker.yml
More file actions
154 lines (131 loc) · 4.4 KB
/
Copy pathtasks_docker.yml
File metadata and controls
154 lines (131 loc) · 4.4 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#
- name: Docker | Check if is present
command: test -x /usr/bin/docker
ignore_errors: yes
register: docker_present
changed_when: False
tags:
-docker
- debug: var="ansible_distribution"
- debug: var="ansible_os_family"
- name: Debian docker install
block:
- name: Remove specified packages
apt:
state: absent
name: "{{ item }}"
become: true
loop:
- docker.io
- docker-doc
- docker-compose
- docker-compose-v2
- podman-docker
- containerd
- runc
- name: Install docker-credential-pass helper
get_url:
url: https://github.com/docker/docker-credential-helpers/releases/download/v0.8.2/docker-credential-pass-v0.8.2.linux-amd64
dest: /usr/local/bin/docker-credentials-pass
mode: '0755'
become: true
# alternatively: https://amazon-ecr-credential-helper-releases.s3.us-east-2.amazonaws.com/0.9.0/linux-amd64/docker-credential-ecr-login
- name: Install ECR credentials helper
apt:
state: present
name: "{{ item }}"
become: true
loop:
- amazon-ecr-credential-helper
- name: Install ca-certificates and curl
apt:
name:
- ca-certificates
- curl
state: present
update_cache: yes
become: true
- name: Create directory /etc/apt/keyrings with permissions 0755
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
become: true
- name: Download Docker GPG key to /etc/apt/keyrings/docker.asc
get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.asc
mode: '0644'
become: true
- name: Ensure file permissions are set to a+r (world-readable) on /etc/apt/keyrings/docker.asc
file:
path: /etc/apt/keyrings/docker.asc
mode: '0644'
become: true
- name: Get architecture
command: dpkg --print-architecture
register: architecture_result
- name: Get OS codename
shell: bash -c '. /etc/os-release && echo "$VERSION_CODENAME"'
register: codename_result
become: true
- debug: msg="Arch detected {{ architecture_result.stdout }}"
- debug: msg="Code name detected {{ codename_result.stdout }}"
- name: Add Docker repository to sources list
copy:
content: |
deb [arch={{ architecture_result.stdout }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ codename_result.stdout }} stable
dest: /etc/apt/sources.list.d/docker.list
mode: '0644'
become: true
- name: Update apt package index
apt:
update_cache: yes
become: true
- name: Install Docker packages
apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: yes
become: yes
- name: Run hello-world container
command: docker run hello-world
register: result
failed_when: "'Hello from Docker!' not in result.stdout"
changed_when: false
become: true
- name: Assert hello-world container ran successfully
assert:
that:
- "'Hello from Docker!' in result.stdout"
msg: "Docker hello-world container did not run successfully"
become: true
- debug: msg="Adding {{ ansible_user_id }} to docker group"
- name: Add the current user to the Docker group
user:
name: "{{ ansible_user_id }}"
groups: docker
append: yes
become: yes
# ctop
- name: Add GPG key for docker-ctop repository
ansible.builtin.apt_key:
url: https://azlux.fr/repo.gpg
state: present
become: true
- name: Add docker-ctop APT repository
ansible.builtin.apt_repository:
repo: "deb http://packages.azlux.fr/debian stable main"
state: present
become: true
- name: Update APT package index
ansible.builtin.apt:
name: docker-ctop
update_cache: yes
become: true
when: ansible_os_family == 'Debian'