2022-12-29 21:13:31 +00:00
|
|
|
# vim: ft=yaml.ansible
|
2024-03-01 20:30:18 +00:00
|
|
|
# code: language=ansible
|
2018-05-10 09:19:54 +00:00
|
|
|
---
|
2024-03-30 19:09:03 +00:00
|
|
|
- name: Add Docker apt PGP key
|
|
|
|
ansible.builtin.apt_key:
|
|
|
|
id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88
|
|
|
|
url: https://download.docker.com/linux/debian/gpg
|
2018-05-10 09:19:54 +00:00
|
|
|
state: present
|
|
|
|
|
2023-10-04 20:05:59 +00:00
|
|
|
- name: Add Docker apt repository
|
2024-03-30 19:09:03 +00:00
|
|
|
ansible.builtin.apt_repository:
|
|
|
|
filename: docker
|
|
|
|
repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable"
|
2018-05-10 09:19:54 +00:00
|
|
|
state: present
|
2024-03-30 18:16:29 +00:00
|
|
|
update_cache: true
|
2018-05-10 09:19:54 +00:00
|
|
|
|
2023-10-04 20:05:59 +00:00
|
|
|
- name: Install Docker
|
2024-03-30 23:08:06 +00:00
|
|
|
ansible.builtin.apt:
|
2024-03-30 18:16:29 +00:00
|
|
|
name:
|
2024-03-30 23:09:35 +00:00
|
|
|
- containerd.io
|
2023-10-04 20:05:59 +00:00
|
|
|
- docker-ce
|
2024-03-30 19:09:03 +00:00
|
|
|
- docker-ce-cli
|
|
|
|
- docker-buildx-plugin
|
2023-10-04 20:05:59 +00:00
|
|
|
- docker-compose-plugin
|
2024-03-30 18:16:29 +00:00
|
|
|
state: present
|
2023-10-04 20:05:59 +00:00
|
|
|
|
2024-03-31 17:31:27 +00:00
|
|
|
- name: Create group for Docker socket
|
|
|
|
ansible.builtin.group:
|
|
|
|
name: docker
|
|
|
|
state: present
|
|
|
|
|
2024-03-30 19:09:03 +00:00
|
|
|
- name: Configure rootful Docker
|
|
|
|
when: not docker_rootless
|
|
|
|
block:
|
|
|
|
- name: Make sure Docker is running
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: docker
|
|
|
|
enabled: true
|
2024-03-31 17:31:27 +00:00
|
|
|
state: started
|
2024-03-30 19:09:03 +00:00
|
|
|
|
|
|
|
- name: Configure cron job to prune unused Docker data weekly
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: Prune unused Docker data
|
|
|
|
cron_file: ansible_docker_prune
|
|
|
|
job: docker system prune -fa --volumes --filter "until=6h"
|
|
|
|
special_time: weekly
|
|
|
|
user: root
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Configure rootless Docker
|
|
|
|
when: docker_rootless
|
|
|
|
block:
|
|
|
|
- name: Make sure rootful Docker is stopped and disabled
|
|
|
|
ansible.builtin.systemd_service:
|
|
|
|
name: docker
|
|
|
|
enabled: false
|
2024-03-31 17:31:27 +00:00
|
|
|
scope: system
|
|
|
|
state: stopped
|
2024-03-30 19:09:03 +00:00
|
|
|
|
|
|
|
- name: Install packages needed by rootless Docker
|
|
|
|
ansible.builtin.apt:
|
|
|
|
name:
|
|
|
|
- docker-ce-rootless-extras
|
|
|
|
- uidmap
|
|
|
|
- dbus-user-session
|
|
|
|
- fuse-overlayfs
|
|
|
|
- slirp4netns
|
2024-03-31 01:58:25 +00:00
|
|
|
state: present
|
2024-03-30 19:09:03 +00:00
|
|
|
|
2024-03-30 23:08:06 +00:00
|
|
|
- name: Create user for rootless Docker
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ docker_rootless_user }}"
|
|
|
|
uid: "{{ docker_rootless_user_uid }}"
|
|
|
|
comment: Rootless Docker User
|
|
|
|
groups:
|
|
|
|
- docker
|
|
|
|
state: present
|
|
|
|
|
2024-03-30 19:09:03 +00:00
|
|
|
- name: Enable lingering for Docker user
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: loginctl enable-linger {{ docker_rootless_user }}
|
|
|
|
creates: /var/lib/systemd/linger/{{ docker_rootless_user }}
|
|
|
|
|
2024-03-30 23:08:06 +00:00
|
|
|
- name: Set DOCKER_HOST environment variable globally
|
2024-03-30 19:09:03 +00:00
|
|
|
ansible.builtin.lineinfile:
|
2024-03-30 23:08:06 +00:00
|
|
|
path: /etc/profile
|
2024-03-30 19:09:03 +00:00
|
|
|
regexp: '^export DOCKER_HOST='
|
|
|
|
line: export DOCKER_HOST=unix:///run/user/{{ docker_rootless_user_uid }}/docker.sock
|
|
|
|
state: present
|
2024-03-30 23:08:06 +00:00
|
|
|
|
|
|
|
- name: Run rootless Docker setup script
|
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: dockerd-rootless-setuptool.sh install
|
|
|
|
creates: /home/{{ docker_rootless_user }}/.config/systemd/user/docker.service
|
2024-03-30 19:09:03 +00:00
|
|
|
become: true
|
|
|
|
become_user: "{{ docker_rootless_user }}"
|
|
|
|
|
|
|
|
- name: Make sure rootless Docker is running
|
|
|
|
ansible.builtin.systemd_service:
|
|
|
|
name: docker.service
|
|
|
|
enabled: true
|
2024-03-31 17:31:27 +00:00
|
|
|
scope: user
|
|
|
|
state: started
|
2024-03-30 19:09:03 +00:00
|
|
|
become: true
|
|
|
|
become_user: "{{ docker_rootless_user }}"
|
2023-07-07 16:15:01 +00:00
|
|
|
|
2024-03-30 19:09:03 +00:00
|
|
|
- name: Configure cron job to prune unused Docker data weekly
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: Prune unused Docker data
|
|
|
|
cron_file: ansible_docker_rootless_prune
|
|
|
|
job: docker --host unix:///run/user/{{ docker_rootless_user_uid }}/docker.sock system prune -fa --volumes --filter "until=6h"
|
|
|
|
special_time: weekly
|
|
|
|
user: "{{ docker_rootless_user }}"
|
|
|
|
state: present
|