fix: Ensure container starts at boot

This commit is contained in:
pulsar89.5 2024-06-09 16:10:19 +02:00
parent 1da27ec5a2
commit 4e1585446f
2 changed files with 30 additions and 13 deletions

View File

@ -30,14 +30,3 @@
state: restarted state: restarted
name: rsyslog.service name: rsyslog.service
become: true become: true
- name: Redémarrer le conteneur
ansible.builtin.systemd:
name: "{{ item.name }}"
state: restarted
scope: true
daemon_reload: true
become: true
loop: "{{ podman_containers }}"
loop_control:
label: "{{ item.name }}"

View File

@ -12,7 +12,21 @@
vars: vars:
container_user: "podman-{{ item.user | default(item.name) }}" container_user: "podman-{{ item.user | default(item.name) }}"
- name: Déployer le conteneur - 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
containers.podman.podman_container: containers.podman.podman_container:
hostname: "{{ item.hostname | default(inventory_hostname) }}" hostname: "{{ item.hostname | default(inventory_hostname) }}"
name: "{{ item.name }}" name: "{{ item.name }}"
@ -29,9 +43,23 @@
recreate: true recreate: true
become: true become: true
become_user: "{{ container_user }}" become_user: "{{ container_user }}"
register: deploy_container
loop: "{{ podman_containers }}" loop: "{{ podman_containers }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
vars: vars:
container_user: "podman-{{ item.user | default(item.name) }}" container_user: "podman-{{ item.user | default(item.name) }}"
notify: Redémarrer le conteneur
- 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) }}"