-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbook_Dockerinstall.yml
94 lines (80 loc) · 2.89 KB
/
playbook_Dockerinstall.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
85
86
87
88
89
90
91
92
93
94
- name: working on vm frosty
hosts: vm
become: true
tasks:
- name: Install the packages dependencies
ansible.builtin.apt:
name:
- ca-certificates
- curl
- gnupg
- lsb-release
state: latest
update_cache: true
- name: check if dependencies are installed
ansible.builtin.shell: dpkg -l 'ca-certificates' && dpkg -l 'curl' && dpkg -l 'gnupg' && dpkg -l 'lsb-release'
register: certificates
failed_when: certificates.stderr != ''
changed_when: false
- name: add keyrings directory
ansible.builtin.file:
path: /etc/apt/keyrings
state: directory
- name: add docker apt key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
keyring: /etc/apt/keyrings/docker.gpg
- name: check if gpg key is installed
ansible.builtin.shell: apt-key adv --list-public-keys --with-fingerprint --with-colons | grep docker
register: dockergpg
changed_when: false
- name: Add specified repository into sources list
ansible.builtin.apt_repository:
repo: deb https://download.docker.com/linux/ubuntu focal state
state: present
- name: check added docker repository
ansible.builtin.shell: cat "/etc/apt/sources.list.d/Docker.list"
register: dockerrepo
failed_when: dockerrepo.stderr != ''
changed_when: false
- name: apt-get update
ansible.builtin.shell: sudo apt-get update
- name: Install the package "docker"
ansible.builtin.apt:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-compose-plugin
state: latest
# update_cache: true ist das äqivalent zu apt-get update
- name: check if docker components are installed
ansible.builtin.shell: dpkg -l 'docker-ce' && dpkg -l 'docker-ce-cli' && dpkg -l 'containerd.io' && dpkg -l 'docker-compose-plugin'
register: dockercomponents
failed_when: dockercomponents.stderr != ''
changed_when: false
- name: Is docker running
ansible.builtin.service:
name: docker
state: started
- name: Add the user "snowman" to docker group
ansible.builtin.user:
name: snowman
comment: user of the vm
uid: 1000
group: docker
- name: check if user is added to docker group
ansible.builtin.shell: id -nG snowman | grep -o docker
register: dockeruser
failed_when: dockeruser.stderr != ''
changed_when: false
- name: run Hello-world container
community.docker.docker_container:
name: hello-world_Ulli
image: hello-world
- name: check if hello-world container is running
ansible.builtin.shell: docker ps | grep hello-world
register: hello
failed_when: hello.stderr != ''
changed_when: false