vps/roles/dockerd/tasks/main.yml

81 lines
2.5 KiB
YAML

- name: Make sure required packages are installed
apt:
name:
- dbus-user-session
- docker.io
- docker-compose
- rootlesskit
- slirp4netns
- uidmap
become: true
- name: Make sure system-wide Docker daemon & socket are stopped & disabled
service:
name: "{{ item }}"
state: stopped
enabled: false
loop:
- docker
- docker.socket
become: true
- name: Get docker user service status
stat:
path: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service"
register: dockerd_user_service_file_result
- name: Run dockerd-rootless-setuptool.sh script
command:
cmd: /usr/share/docker.io/contrib/dockerd-rootless-setuptool.sh install
# Don't run install script everytime
when: not dockerd_user_service_file_result.stat.exists
- name: Make sure /usr/share/docker.io/contrib is in PATH variable
lineinfile:
path: "{{ ansible_env['HOME'] }}/.profile"
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:
path: "{{ ansible_env['HOME'] }}/.profile"
regex: '^export DOCKER_HOST='
line: "export DOCKER_HOST={{ docker_host }}"
- name: "Make sure lingering is enabled for user {{ host_uid }}"
command:
cmd: "loginctl enable-linger {{ host_uid }}"
become: true
- name: "Create directory {{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d"
file:
path: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d"
state: directory
# 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"
copy:
src: "{{ role_path }}/files/override.conf"
dest: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d/override.conf"
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
- name: Start/restart & enable Docker user service
service:
name: docker
scope: user
# Restart only if config file(s) changed
state: "{{ (dockerd_copy_override_conf_result.changed) | ternary('restarted', 'started') }}"
enabled: true