blob: 27e78d45fa7dfc63d45752e695117243a700d82e (
plain) (
blame)
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
|
- name: Read Docker config
block:
- name: Read daemon.json
become: true
ansible.builtin.slurp:
src: /etc/docker/daemon.json
register: docker_current_config
- name: Parse daemon.json
ansible.builtin.set_fact:
docker_current_config: '{{ docker_current_config.content | b64decode | from_json }}'
rescue:
- name: daemon.json is missing
ansible.builtin.set_fact:
docker_current_config: {}
- name: Modify Docker config
become: true
block:
- name: Create /etc/docker
ansible.builtin.file:
path: /etc/docker
state: directory
owner: root
group: root
mode: '755'
- name: Write daemon.json
ansible.builtin.copy:
dest: /etc/docker/daemon.json
content: '{{ docker_current_config | combine({"log-driver": docker_logging_driver}) | to_nice_json }}'
owner: root
group: root
mode: '644'
register: docker_config
- name: Restart Docker if necessary
become: true
when: docker_config.changed
block:
- name: Collect service facts
ansible.builtin.service_facts:
- name: Restart Docker service
when: |
'docker.service' in ansible_facts.services and ansible_facts.services['docker.service'].state == 'running'
ansible.builtin.systemd_service:
name: docker
state: restarted
|