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

47 lines
1.2 KiB
YAML
Raw Normal View History

2023-10-29 19:46:52 +00:00
# vim: ft=yaml.ansible
# code: language=ansible
---
- name: Add Docker PGP key
ansible.builtin.apt_key:
keyserver: keyserver.ubuntu.com
id: '0x8D81803C0EBFCD88'
state: present
- name: Add Docker apt repository
ansible.builtin.apt_repository:
repo: 'deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian bullseye stable'
update_cache: true
state: present
- name: Install Docker
ansible.builtin.apt:
name: "{{ pkgs }}"
state: present
vars:
pkgs:
- docker-ce
- docker-compose-plugin
- name: Copy Docker daemon config file
ansible.builtin.template:
src: etc/docker/daemon.json.j2
dest: /etc/docker/daemon.json
owner: root
mode: u=rw,g=r,o=r
2023-11-05 18:08:26 +00:00
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