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

46 lines
1.2 KiB
YAML

# vim: ft=yaml.ansible
# code: language=ansible
---
- 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
state: present
- name: Install Docker and Docker Compose
ansible.builtin.dnf:
name:
- docker-ce
- docker-ce-cli
- docker-compose-plugin
- containerd.io
state: present
- name: Copy Docker daemon config file
ansible.builtin.copy:
src: daemon.json
dest: /etc/docker/daemon.json
owner: root
mode: u=rw,g=r,o=r
notify: Reload Docker daemon
- name: Ensure Docker daemon is enabled and running
ansible.builtin.service:
name: docker
enabled: true
state: started
- name: Configure cron job to prune unused Docker data daily
ansible.builtin.cron:
name: Prune unused Docker data
cron_file: ansible_docker_prune
job: 'docker system prune -fa && docker volume prune -fa'
special_time: daily
user: root
state: present