ansible-role-docker_host/tasks/main.yml

111 lines
2.8 KiB
YAML
Raw Normal View History

2024-04-06 20:21:07 +02:00
- name: Install packages
ansible.builtin.package:
name: "{{ item }}"
state: present
2022-03-21 14:22:19 +01:00
with_items:
- gpg
2024-04-06 20:21:07 +02:00
- name: Add docker apt-key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
2022-03-21 14:22:19 +01:00
2024-04-06 20:21:07 +02:00
- name: Add docker apt repository
ansible.builtin.apt_repository:
repo: 'deb https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable'
state: present
2022-03-21 14:22:19 +01:00
filename: docker
2024-04-06 20:21:07 +02:00
update_cache: true
2022-03-21 14:22:19 +01:00
2024-04-06 20:21:07 +02:00
- name: Install packages
ansible.builtin.package:
name:
- docker-ce
- docker-ce-cli
- containerd.io
- python3-pip
state: present
2022-03-21 14:22:19 +01:00
2024-04-06 20:21:07 +02:00
- name: Configure user dockremap
ansible.builtin.user:
2022-03-21 14:22:19 +01:00
name: dockremap
state: present
shell: /bin/false
2024-04-06 20:21:07 +02:00
- name: Configure namespaces dans grub
ansible.builtin.lineinfile:
2022-03-21 14:22:19 +01:00
state: present
dest: /etc/default/grub
2024-04-06 20:21:07 +02:00
backrefs: true
regexp: '^GRUB_CMDLINE_LINUX="((.*?)namespace\.unpriv_enable=1 user_namespace\.enable=1)?\s?(.*?)$'
line: 'GRUB_CMDLINE_LINUX="\2namespace.unpriv_enable=1 user_namespace.enable=1 \3'
register: _grub_config
- name: Configure update grub
ansible.builtin.command: "{{ update_grub_command }}"
when: _grub_config.changed # noqa: no-handler
changed_when: true
- name: Configure execute handlers maintenant, avant possible reboot
ansible.builtin.meta: flush_handlers
- name: Configure sysctl user_namespaces
ansible.posix.sysctl:
name: user.max_user_namespaces
value: 15076
sysctl_set: true
state: present
reload: true
- name: Configure docker daemon.json
ansible.builtin.template:
2022-03-21 14:22:19 +01:00
src: daemon.json.j2
dest: /etc/docker/daemon.json
2024-04-06 20:21:07 +02:00
mode: u=rw,g=r,o=r
2022-03-21 14:22:19 +01:00
notify:
2024-04-06 20:21:07 +02:00
- Restart docker
2022-03-21 14:22:19 +01:00
2024-04-06 20:21:07 +02:00
- name: REBOOT IMMEDIAT pour prise en compte configuration, relancer le playbook s'il ne poursuit pas tout seul
ansible.builtin.reboot:
when: _grub_config.changed # noqa: no-handler
2024-04-06 20:21:07 +02:00
- name: Active docker
ansible.builtin.service:
2022-03-21 14:22:19 +01:00
name: docker
state: started
2024-04-06 20:21:07 +02:00
enabled: true
2022-03-21 14:22:19 +01:00
- name: Configure tâche cron pour docker system prune
ansible.builtin.template:
src: docker_prune.j2
dest: /etc/cron.daily/docker_prune
mode: u=rwx,g=rx,o=rx
2024-04-06 20:21:07 +02:00
- name: Traefik network
community.docker.docker_network:
2022-03-21 14:22:19 +01:00
name: traefik
when: docker_host_traefik_enabled
2024-04-06 20:21:07 +02:00
- name: Traefik dir
ansible.builtin.file:
2022-03-21 14:22:19 +01:00
path: /opt/traefik
state: directory
2024-04-06 20:21:07 +02:00
mode: u=rwx,g=rx,o=
2022-03-21 14:22:19 +01:00
when: docker_host_traefik_enabled
2024-04-06 20:21:07 +02:00
- name: Traefik compose
ansible.builtin.template:
2022-03-21 14:22:19 +01:00
src: traefik-docker-compose.yml.j2
dest: /opt/traefik/docker-compose.yml
2024-04-06 20:21:07 +02:00
mode: u=rw,g=r,o=r
2022-03-21 14:22:19 +01:00
register: traefik_compose_file
when: docker_host_traefik_enabled
2024-04-06 20:21:07 +02:00
- name: Traefik run
ansible.builtin.command: "docker compose up -d"
2022-03-21 14:22:19 +01:00
args:
chdir: /opt/traefik/
when: docker_host_traefik_enabled and traefik_compose_file.changed