2024-02-17 19:01:04 +01:00
|
|
|
- name: Make sure required packages are installed
|
|
|
|
apt:
|
|
|
|
name:
|
|
|
|
- docker.io
|
|
|
|
- docker-compose
|
|
|
|
- rootlesskit
|
|
|
|
- slirp4netns
|
|
|
|
- uidmap
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: Make sure system-wide Docker daemon is stopped & disabled
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: stopped
|
|
|
|
enabled: false
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: Make sure system-wide Docker socket is stopped & disabled
|
|
|
|
service:
|
|
|
|
name: docker.socket
|
|
|
|
state: stopped
|
|
|
|
enabled: false
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: Run dockerd-rootless-setuptool.sh script
|
|
|
|
command:
|
|
|
|
cmd: /usr/share/docker.io/contrib/dockerd-rootless-setuptool.sh install
|
|
|
|
|
|
|
|
- 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='
|
|
|
|
line: "export DOCKER_HOST=unix:///run/user/{{ host_uid }}/docker.sock"
|
|
|
|
|
|
|
|
- name: "Make sure lingering is enabled for user {{ ansible_env['USER'] }}"
|
|
|
|
command:
|
|
|
|
cmd: "loginctl enable-linger {{ ansible_env['USER'] }}"
|
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: "Create directory {{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d to override environment variables"
|
|
|
|
file:
|
|
|
|
path: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d"
|
|
|
|
state: directory
|
|
|
|
|
|
|
|
- name: Add environment variables to Docker user service to use slirp4netns RootlessKit port driver, which enables source IP propagation
|
|
|
|
copy:
|
|
|
|
dest: "{{ ansible_env['HOME'] }}/.config/systemd/user/docker.service.d/override.conf"
|
|
|
|
content: |
|
|
|
|
[Service]
|
|
|
|
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_NET=slirp4netns"
|
|
|
|
Environment="DOCKERD_ROOTLESS_ROOTLESSKIT_PORT_DRIVER=slirp4netns"
|
|
|
|
|
|
|
|
- name: Start/restart & enable Docker user service
|
|
|
|
service:
|
|
|
|
name: docker
|
|
|
|
state: restarted
|
|
|
|
enabled: true
|