2018-12-12 22:25:36 +00:00
|
|
|
---
|
|
|
|
- block:
|
|
|
|
- name: Add docker group
|
|
|
|
group:
|
|
|
|
name: docker
|
|
|
|
state: present
|
|
|
|
notify: __docker_restart
|
2019-06-10 11:56:17 +00:00
|
|
|
when: dockerengine_docker_group_enabled | bool
|
2018-12-12 22:25:36 +00:00
|
|
|
|
2019-07-16 14:55:25 +00:00
|
|
|
- name: Add namespace group
|
|
|
|
group:
|
2019-07-16 15:21:48 +00:00
|
|
|
name: "{{ dockerengine_nsremap_user }}"
|
2019-08-04 11:36:33 +00:00
|
|
|
state: present
|
|
|
|
when: dockerengine_usernamespace_enabled | bool
|
2019-07-16 14:55:25 +00:00
|
|
|
|
2019-08-04 12:32:15 +00:00
|
|
|
- name: Setup namespace user
|
2019-07-16 14:55:25 +00:00
|
|
|
user:
|
2019-07-16 15:21:48 +00:00
|
|
|
name: "{{ dockerengine_nsremap_user }}"
|
|
|
|
group: "{{ dockerengine_nsremap_user }}"
|
2019-07-16 14:55:25 +00:00
|
|
|
shell: /sbin/nologin
|
|
|
|
state: "{{ 'present' if dockerengine_usernamespace_enabled | bool else 'absent' }}"
|
|
|
|
|
2019-08-04 11:42:05 +00:00
|
|
|
- name: Remove namespace group
|
2019-08-04 11:36:33 +00:00
|
|
|
group:
|
|
|
|
name: "{{ dockerengine_nsremap_user }}"
|
|
|
|
state: absent
|
|
|
|
when: not dockerengine_usernamespace_enabled | bool
|
|
|
|
|
2019-07-16 14:55:25 +00:00
|
|
|
- name: Configure namespace id range
|
|
|
|
lineinfile:
|
|
|
|
dest: "{{ item }}"
|
2019-07-16 15:21:48 +00:00
|
|
|
regexp: "^{{ dockerengine_nsremap_user }}:"
|
|
|
|
line: "{{ dockerengine_nsremap_user }}:{{ dockerengine_nsremap_range_start }}:{{ dockerengine_nsremap_range_length }}"
|
2019-07-16 14:55:25 +00:00
|
|
|
state: "{{ 'present' if dockerengine_usernamespace_enabled | bool else 'absent' }}"
|
|
|
|
loop:
|
|
|
|
- /etc/subuid
|
|
|
|
- /etc/subgid
|
|
|
|
|
2023-02-18 14:14:39 +00:00
|
|
|
- name: Create required directories
|
|
|
|
loop:
|
|
|
|
- name: /etc/systemd/system/docker.service.d
|
|
|
|
mode: "0755"
|
|
|
|
- name: /etc/docker
|
|
|
|
mode: "0755"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.name }}"
|
|
|
|
file:
|
|
|
|
path: "{{ item.name }}"
|
|
|
|
state: directory
|
|
|
|
mode: "{{ item.mode }}"
|
|
|
|
|
2023-02-18 15:01:45 +00:00
|
|
|
- name: Write environment file
|
|
|
|
template:
|
|
|
|
src: etc/sysconfig/docker.j2
|
|
|
|
dest: /etc/sysconfig/docker
|
|
|
|
mode: 0600
|
|
|
|
notify: __docker_restart
|
|
|
|
|
2023-02-18 14:14:39 +00:00
|
|
|
- name: Write service override.conf
|
|
|
|
template:
|
|
|
|
src: etc/systemd/system/docker.service.d/override.conf.j2
|
|
|
|
dest: /etc/systemd/system/docker.service.d/override.conf
|
|
|
|
mode: 0644
|
|
|
|
notify: __docker_restart
|
|
|
|
|
|
|
|
- name: Deploy daemon config
|
|
|
|
copy:
|
|
|
|
content: "{{ (dockerengine_daemon_config | combine(dockerengine_daemon_config_extra)) | to_nice_json }}"
|
|
|
|
dest: /etc/docker/daemon.json
|
|
|
|
mode: 0600
|
|
|
|
notify: __docker_restart
|
|
|
|
|
2020-06-15 19:37:21 +00:00
|
|
|
- name: Ensure docker engine is up and running
|
|
|
|
service:
|
|
|
|
name: "{{ dockerengine_service }}"
|
|
|
|
enabled: True
|
|
|
|
state: started
|
|
|
|
|
2022-01-28 10:31:12 +00:00
|
|
|
- name: Handle registry logins
|
|
|
|
docker_login:
|
|
|
|
registry: "{{ item.url | default(omit) }}"
|
|
|
|
username: "{{ item.username }}"
|
|
|
|
password: "{{ item.password }}"
|
|
|
|
reauthorize: "{{ item.reauthorize | default(False) }}"
|
|
|
|
state: '{{ item.state | default("present") }}'
|
|
|
|
loop: "{{ dockerengine_registries }}"
|
|
|
|
loop_control:
|
2022-01-28 10:49:18 +00:00
|
|
|
label: "{{ item.url | default('DockerHub') }}"
|
2022-01-28 10:31:12 +00:00
|
|
|
|
2020-06-15 06:18:44 +00:00
|
|
|
- name: Create docker networks
|
|
|
|
docker_network:
|
|
|
|
name: "{{ item.name }}"
|
2020-06-15 06:23:32 +00:00
|
|
|
driver: "{{ item.driver | default('bridge') }}"
|
2020-06-15 06:18:44 +00:00
|
|
|
enable_ipv6: "{{ item.enable_ipv6 | default(False) }}"
|
|
|
|
ipam_config: "{{ item.ipam_config | default(omit) }}"
|
|
|
|
force: "{{ item.force | default(omit) }}"
|
|
|
|
state: "{{ item.state | default('present') }}"
|
|
|
|
loop: "{{ dockerengine_networks + dockerengine_networks_extra }}"
|
|
|
|
loop_control:
|
|
|
|
label: "{{ item.name }}"
|
|
|
|
notify: __docker_restart
|
2018-12-12 22:25:36 +00:00
|
|
|
become: True
|
|
|
|
become_user: root
|