2020-08-11 20:01:36 +02:00
|
|
|
---
|
|
|
|
- name: Docker configuration and service management
|
|
|
|
block:
|
|
|
|
- name: Install the Docker default options
|
|
|
|
template: src=docker-default.j2 dest={{ docker_defaults_file }} owner=root group=root mode=0644
|
|
|
|
when: ansible_service_mgr != 'systemd'
|
|
|
|
notify: Restart docker
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: ['docker', 'docker_conf']
|
2020-08-11 20:01:36 +02:00
|
|
|
|
|
|
|
- name: Install the Docker daemon config
|
|
|
|
template: src=daemon.json.j2 dest=/etc/docker/daemon.json owner=root group=root mode=0644
|
|
|
|
notify: Restart docker
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: ['docker', 'docker_conf']
|
2020-08-11 20:01:36 +02:00
|
|
|
|
|
|
|
- name: Create the docker service systemd directory
|
|
|
|
file: dest=/etc/systemd/system/docker.service.d state=directory mode=0755
|
|
|
|
when: ansible_service_mgr == 'systemd'
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: ['docker', 'docker_systemd', 'docker_conf']
|
2020-08-11 20:01:36 +02:00
|
|
|
|
|
|
|
- name: Install the Docker additional systemd unit
|
2022-05-21 19:22:06 +02:00
|
|
|
template:
|
|
|
|
src: docker-systemd-override.conf.j2
|
|
|
|
dest: /etc/systemd/system/docker.service.d/override.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0644
|
2020-08-11 20:01:36 +02:00
|
|
|
when: ansible_service_mgr == 'systemd'
|
|
|
|
notify: Restart docker
|
|
|
|
register: reload_systemd
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: ['docker', 'docker_systemd', 'docker_conf']
|
2020-08-11 20:01:36 +02:00
|
|
|
|
|
|
|
- name: systemd reload
|
|
|
|
command: systemctl daemon-reload
|
|
|
|
when: reload_systemd is defined and reload_systemd is changed
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: ['docker', 'docker_systemd', 'docker_conf']
|
2020-08-11 20:01:36 +02:00
|
|
|
|
|
|
|
- name: Ensure that the service is started and enabled
|
|
|
|
service: name=docker state=started enabled=yes
|
|
|
|
|
2020-08-13 16:12:18 +02:00
|
|
|
when: docker_install
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: [docker]
|
2020-08-11 20:01:36 +02:00
|
|
|
|
2022-05-21 19:45:46 +02:00
|
|
|
- name: Cron job that prunes the dangling images
|
|
|
|
block:
|
|
|
|
- name: Install a script that prunes the docker dangling images
|
|
|
|
copy:
|
|
|
|
src: docker-prune-dangling-images.sh
|
|
|
|
dest: /usr/local/sbin/docker-prune-dangling-images
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: 0744
|
|
|
|
|
|
|
|
- name: Install a cron job that prunes the docker images
|
|
|
|
cron:
|
|
|
|
name: Prune docker images
|
|
|
|
cron_file: docker-prune-images
|
|
|
|
special_time: daily
|
|
|
|
user: root
|
|
|
|
state: present
|
|
|
|
job: "/usr/local/sbin/docker-prune-dangling-images"
|
|
|
|
when: docker_prune_dangling_images
|
|
|
|
|
|
|
|
- name: Disable the cron job that prunes the docker images
|
|
|
|
cron:
|
|
|
|
name: Prune docker images
|
|
|
|
cron_file: docker-prune-images
|
|
|
|
special_time: daily
|
|
|
|
user: root
|
|
|
|
state: absent
|
|
|
|
job: "/usr/local/sbin/docker-prune-dangling-images"
|
|
|
|
when: not docker_prune_dangling_images
|
|
|
|
|
|
|
|
when: docker_install
|
|
|
|
tags: [docker, docker_prune_images]
|
|
|
|
|
2020-08-11 20:01:36 +02:00
|
|
|
- block:
|
|
|
|
- name: Remove the docker user
|
|
|
|
user: name=docker state=absent
|
|
|
|
|
2020-08-13 16:12:18 +02:00
|
|
|
when: not docker_install
|
2022-05-21 19:22:06 +02:00
|
|
|
tags: [docker]
|