add daemon file template

This commit is contained in:
vincent 2023-11-01 09:55:11 +01:00
parent 2e5ad45315
commit eb59034462
3 changed files with 37 additions and 13 deletions

View File

@ -8,3 +8,9 @@ docker_restart_handler_state: restarted
# A list of users who will be added to the docker group.
docker_users: []
## yaml docker config convert in json in template
# exemaple:
# docker_daemon_config:
# dns:
# - 172.17.0.1
docker_daemon_config:

View File

@ -1,32 +1,49 @@
- name: Include OS-specific variables.
include_vars: "{{ ansible_os_family }}.yml"
ansible.builtin.include_vars: "{{ ansible_os_family }}.yml"
- name: Add CentOS repository
when: ansible_os_family == "RedHat"
become: true
block:
- name: Add Docker repository.
get_url:
ansible.builtin.get_url:
url: "https://download.docker.com/linux/centos/docker-ce.repo"
dest: '/etc/yum.repos.d/docker-ce.repo'
owner: root
group: root
mode: 0644
when: ansible_os_family == "RedHat"
become: true
mode: "0644"
- name: Install Docker.
package:
ansible.builtin.package:
name: "{{ docker_package }}"
state: present
notify: restart docker
become: true
- name: Ensure /etc/docker exist
ansible.builtin.file:
dest: /etc/docker/
owner: root
group: root
mode: "0755"
state: directory
become: true
- name: Template daemon.json
ansible.builtin.template:
dest: /etc/docker/daemon.json
src: template/daemon.json.j2
mode: "0644"
notify: restart docker
become: true
- name: Ensure Docker is started and enabled at boot.
service:
ansible.builtin.service:
name: docker
state: "{{ docker_service_state }}"
enabled: "{{ docker_service_enabled }}"
become: true
- include_tasks: docker-users.yml
- name: Include Users task
ansible.builtin.include_tasks: docker-users.yml
when: docker_users | length > 0

1
template/daemon.json.j2 Normal file
View File

@ -0,0 +1 @@
{{ docker_daemon_config|to_json(indent=4) }}