vps/roles/dockerd/tasks/main.yml

82 lines
2.5 KiB
YAML
Raw Normal View History

2024-02-17 19:01:04 +01:00
- name: Make sure required packages are installed
apt:
name:
2024-02-21 21:56:48 +01:00
- dbus-user-session
2024-02-17 19:01:04 +01:00
- docker.io
- docker-compose
- rootlesskit
- slirp4netns
- uidmap
become: true
2024-02-21 21:56:48 +01:00
- name: Make sure system-wide Docker daemon & socket are stopped & disabled
2024-02-17 19:01:04 +01:00
service:
2024-02-21 21:56:48 +01:00
name: "{{ item }}"
2024-02-17 19:01:04 +01:00
state: stopped
enabled: false
2024-02-21 21:56:48 +01:00
loop:
- docker
- docker.socket
2024-02-17 19:01:04 +01:00
become: true
2024-02-21 21:56:48 +01:00
- name: Get docker user service status
stat:
path: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service"
register: dockerd_user_service_file_result
2024-02-17 19:01:04 +01:00
- name: Run dockerd-rootless-setuptool.sh script
command:
cmd: /usr/share/docker.io/contrib/dockerd-rootless-setuptool.sh install
2024-02-21 21:56:48 +01:00
# Don't run install script everytime
when: not dockerd_user_service_file_result.stat.exists
2024-02-17 19:01:04 +01:00
- name: Make sure /usr/share/docker.io/contrib is in PATH variable
lineinfile:
2024-02-17 19:06:41 +01:00
path: "{{ ansible_env['HOME'] }}/.profile"
2024-02-17 19:01:04 +01:00
regex: '^export PATH="/usr/share/docker\.io/contrib'
line: 'export PATH="/usr/share/docker.io/contrib:$PATH"'
- name: Make sure DOCKER_HOST variable is set correctly
lineinfile:
2024-02-17 19:06:41 +01:00
path: "{{ ansible_env['HOME'] }}/.profile"
2024-02-17 19:01:04 +01:00
regex: '^export DOCKER_HOST='
2024-03-30 11:32:39 +01:00
line: "export DOCKER_HOST={{ docker_host }}"
2024-02-17 19:01:04 +01:00
- name: "Make sure lingering is enabled for user {{ host_uid }}"
2024-02-17 19:01:04 +01:00
command:
cmd: "loginctl enable-linger {{ host_uid }}"
2024-02-17 19:01:04 +01:00
become: true
2024-02-21 21:56:48 +01:00
- name: "Create directory {{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d"
2024-02-17 19:01:04 +01:00
file:
path: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d"
state: directory
2024-02-21 21:56:48 +01:00
# Set port driver to slirp4netns to enable source IP propagation, which is required for coturn to work.
- name: "Copy systemd service override.conf to {{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d/override.conf"
2024-02-17 19:01:04 +01:00
copy:
2024-02-21 21:56:48 +01:00
src: "{{ role_path }}/files/override.conf"
2024-02-17 19:01:04 +01:00
dest: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d/override.conf"
2024-02-21 21:56:48 +01:00
register: dockerd_copy_override_conf_result
- name: Edit some sysctl entries for Redis & Syncthing
sysctl:
name: "{{ item.key }}"
value: "{{ item.value }}"
loop:
- key: vm.overcommit_memory
value: 1
- key: net.core.wmem_max
value: 2500000
- key: net.core.rmem_max
value: 2500000
become: true
2024-02-17 19:01:04 +01:00
- name: Start/restart & enable Docker user service
service:
name: docker
2024-02-21 21:56:48 +01:00
scope: user
# Restart only if config file(s) changed
state: "{{ (dockerd_copy_override_conf_result.changed) | ternary('restarted', 'started') }}"
2024-02-17 19:01:04 +01:00
enabled: true