sce/roles/backup_nfs/tasks/per-container-create.yml
Ivo C.S. Wingelaar 3934bffbd1
Add backup restoration logic to NFS role
Passing the `backup_nfs_restore` variable will restore that timestamp.
2024-10-13 20:12:26 +02:00

24 lines
878 B
YAML

---
- name: Ensure container is stopped
ansible.builtin.systemd_service:
name: container-{{ container }}.service
state: stopped
scope: user
register: container_state
- name: Create volume export
containers.podman.podman_export:
volume: "{{ item }}"
dest: "{{ backup_nfs_mountpoint }}/{{ container }}-{{ item }}-{{ ansible_date_time['iso8601_basic_short'] }}.tar"
loop: "{{ backup_nfs_containers['volumes'] }}"
# A container is not always running, so if it was stopped before
# the backup procedure even started, do not start it again.
# It's quite a hassle to have this behaviour with a handler, so
# we just suppress the linting error.
- name: Start container again if necessary # noqa: no-handler
ansible.builtin.systemd_service:
name: container-{{ container }}.service
state: started
scope: user
when: container_state is changed