Properly recreate systemd unit on container update

This commit is contained in:
Thomas Kleinendorst 2024-06-05 16:53:00 +02:00
parent 4fb455c6b4
commit fd2052767d
3 changed files with 9 additions and 9 deletions

View file

@ -1,7 +1,7 @@
---
- name: Reload systemd (daemon-reload)
become: true
become_user: "{{ actual_username }}"
become_user: "{{ container_user }}"
ansible.builtin.systemd_service:
daemon_reload: true
scope: user

View file

@ -37,6 +37,13 @@
containers.podman.podman_container:
name: "{{ podman_container_name }}"
state: absent
- name: Make sure the systemd unit file isn't present
ansible.builtin.file:
path: "/home/{{ container_user }}/.config/systemd/user/container-{{ podman_container_name }}.service"
state: absent
notify: Reload systemd (daemon-reload)
- name: Flush handlers
ansible.builtin.meta: flush_handlers
- name: Map volumes to Podman accepted list
ansible.builtin.set_fact:
volumes: "{{ volumes + ['/home/' + container_user + '/' + item.name + ':' + item.mnt] }}"
@ -60,16 +67,9 @@
notify: Reload systemd (daemon-reload)
- name: Flush handlers
ansible.builtin.meta: flush_handlers
# On restarts this seems to be a bit buggy. Some manual waiting might be necessary and running:
# systemctl --user daemon-reload && systemctl --user start {{ service_name }}
# The retry also doesn't work as of yet. Seems that doing a daemon-reload and then refreshing the task seems to work
- name: Enable the newly created systemd service for user
ansible.builtin.systemd:
name: "container-{{ podman_container_name }}.service"
state: started
enabled: true
scope: user
retries: 3
delay: 3
register: result
until: "'Error.EBUSY' not in result.msg"