role_podman/tasks/configuration.yml

83 lines
2.6 KiB
YAML
Raw Permalink Normal View History

2023-12-21 16:30:57 +00:00
---
# tasks file for podman
2024-06-06 00:39:39 +00:00
- name: Activer le lingering
ansible.builtin.command:
2024-06-07 23:51:45 +00:00
cmd: "loginctl enable-linger {{ container_user }}"
creates: /var/lib/systemd/linger/{{ container_user }}
2024-06-06 00:39:39 +00:00
become: true
2024-06-07 23:51:45 +00:00
loop: "{{ podman_containers }}"
loop_control:
label: "{{ item.name }}"
vars:
container_user: "podman-{{ item.user | default(item.name) }}"
2024-06-06 00:39:39 +00:00
2024-06-09 14:10:19 +00:00
- name: Créer les dossiers des volumes
ansible.builtin.file:
path: "{{ item.1 | split(':') | first }}"
state: directory
owner: "{{ container_user }}"
group: "{{ container_user }}"
mode: u=rwX,g=rX,o=rX
become: true
loop: "{{ q('ansible.builtin.subelements', podman_containers, 'volumes', {'skip_missing': True}) }}"
loop_control:
label: "{{ item.0.name }}"
vars:
container_user: "podman-{{ item.0.user | default(item.0.name) }}"
- name: Déployer les conteneurs
2024-06-06 00:16:51 +00:00
containers.podman.podman_container:
2024-06-07 23:51:45 +00:00
hostname: "{{ item.hostname | default(inventory_hostname) }}"
name: "{{ item.name }}"
image: "{{ item.image }}"
2024-06-06 00:16:51 +00:00
state: quadlet
2024-06-07 23:51:45 +00:00
device: "{{ item.device | default(omit) }}"
ports: "{{ item.ports | default(omit) }}"
volumes: "{{ item.volumes | default(omit) }}"
userns: "{{ item.userns | default(omit) }}"
mount: "{{ item.mount | default(omit) }}"
publish: "{{ item.publish | default(omit) }}"
env: "{{ item.env | default(omit) }}"
quadlet_options: "{{ item.quadlet_options | default(omit) }}"
2024-06-11 16:05:55 +00:00
sysctl: "{{ item.sysctl | default(omit) }}"
cap_add: "{{ item.cap_add | default(omit) }}"
2024-06-06 00:16:51 +00:00
recreate: true
2023-12-21 16:30:57 +00:00
become: true
become_user: "{{ container_user }}"
2024-06-09 14:10:19 +00:00
register: deploy_container
2024-06-07 23:51:45 +00:00
loop: "{{ podman_containers }}"
loop_control:
label: "{{ item.name }}"
vars:
container_user: "podman-{{ item.user | default(item.name) }}"
2024-06-09 14:10:19 +00:00
- name: Démarrer ou redémarrer le conteneur
ansible.builtin.systemd_service:
name: "{{ item.item.name }}.service"
state: "{{ 'restarted' if item.changed else 'started' }}"
daemon_reload: true
scope: user
become: true
become_user: "{{ container_user }}"
loop: "{{ deploy_container.results }}"
loop_control:
label: "{{ item.item.name }}"
vars:
container_user: "podman-{{ item.item.user | default(item.item.name) }}"
2024-06-18 10:36:04 +00:00
- name: Activer le service de mise à jour automatique
ansible.builtin.systemd_service:
name: podman-auto-update.timer
daemon_reload: true
enabled: true
scope: user
when: podman_auto_update
become: true
become_user: "{{ container_user }}"
loop: "{{ deploy_container.results }}"
loop_control:
label: "{{ item.item.name }}"
vars:
container_user: "podman-{{ item.item.user | default(item.item.name) }}"