lab-ansible/roles/docker/tasks/main.yml

59 lines
1.4 KiB
YAML
Raw Normal View History

2023-10-29 19:46:52 +00:00
# vim: ft=yaml.ansible
# code: language=ansible
---
2023-11-12 15:41:59 +00:00
- name: Add Docker repository
ansible.builtin.yum_repository:
name: docker-ce-stable
description: Docker CE Stable - $basearch
file: docker-ce
baseurl: https://download.docker.com/linux/centos/$releasever/$basearch/stable
gpgkey: https://download.docker.com/linux/centos/gpg
gpgcheck: true
enabled: true
2023-10-29 19:46:52 +00:00
state: present
2023-11-12 15:41:59 +00:00
- name: Install Docker and Docker Compose
ansible.builtin.dnf:
name:
2023-10-29 19:46:52 +00:00
- docker-ce
2023-11-12 15:41:59 +00:00
- docker-ce-cli
2023-10-29 19:46:52 +00:00
- docker-compose-plugin
2023-11-12 15:41:59 +00:00
- containerd.io
state: present
2023-10-29 19:46:52 +00:00
2024-01-07 16:29:46 +00:00
- name: Create Docker data root directory
ansible.builtin.file:
path: "{{ docker_data_root }}"
owner: root
2024-01-30 18:15:51 +00:00
group: root
2024-01-07 16:29:46 +00:00
mode: u=rwx,g=x,o=
seuser: system_u
serole: object_r
setype: container_var_lib_t
selevel: s0
2024-01-07 16:29:46 +00:00
state: directory
2023-12-25 20:49:17 +00:00
- name: Copy Docker daemon config file
2024-01-07 16:29:46 +00:00
ansible.builtin.template:
src: daemon.json.j2
2023-12-25 20:49:17 +00:00
dest: /etc/docker/daemon.json
owner: root
2024-01-30 18:15:51 +00:00
group: root
2023-12-25 20:49:17 +00:00
mode: u=rw,g=r,o=r
notify: Reload Docker daemon
2023-10-29 19:46:52 +00:00
- name: Ensure Docker daemon is enabled and running
ansible.builtin.service:
name: docker
enabled: true
state: started
2023-11-11 15:35:14 +00:00
- name: Configure cron job to prune unused Docker data daily
2023-10-29 19:46:52 +00:00
ansible.builtin.cron:
name: Prune unused Docker data
cron_file: ansible_docker_prune
job: 'docker system prune -fa && docker volume prune -fa'
2023-11-11 15:35:14 +00:00
special_time: daily
2023-10-29 19:46:52 +00:00
user: root
state: present