2023-10-25 22:26:17 +02:00
|
|
|
---
|
|
|
|
- name: read config
|
|
|
|
become: true
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: "set -o pipefail && pct config {{ item.vmid }} | grep \"mp{{ item.mp_nr }}: {{ item.mp_path_host }},mp={{ item.mp_path_guest }}\""
|
|
|
|
executable: /bin/bash
|
|
|
|
register: config
|
|
|
|
changed_when: false
|
|
|
|
failed_when: false
|
|
|
|
# prüfe ob bind mount schon vorhanden ist
|
|
|
|
# exit-code wird unten geprüft
|
|
|
|
|
|
|
|
# - name: debug config
|
|
|
|
# ansible.builtin.debug:
|
|
|
|
# msg: "{{ config }}"
|
|
|
|
|
|
|
|
- name: add bind mounts to container # noqa no-changed-when
|
|
|
|
become: true
|
|
|
|
ansible.builtin.command: "pct set {{ item.vmid }} -mp{{ item.mp_nr }} {{ item.mp_path_host }},mp={{ item.mp_path_guest }}"
|
|
|
|
register: restart
|
2023-11-29 22:24:57 +01:00
|
|
|
changed_when:
|
2024-05-02 09:24:28 +02:00
|
|
|
- "(restart.rc == 25) OR (restart.rc == 0)"
|
2023-11-29 22:24:57 +01:00
|
|
|
failed_when:
|
|
|
|
- restart.rc != 25
|
2023-10-25 22:26:17 +02:00
|
|
|
notify: restart lxc
|
|
|
|
# füge bind-mount hinzu falls er fehlt, also rc ungleich 0
|
|
|
|
# pro bind-mount
|
|
|
|
when:
|
|
|
|
- not ansible_check_mode
|
|
|
|
- not config.rc == 0
|
|
|
|
# überspringe wenn in check-mode
|
|
|
|
|
|
|
|
# schreibe vm id in die Liste "reboot"
|
|
|
|
- name: set reboot list # noqa no-handler var-naming[pattern]
|
|
|
|
ansible.builtin.set_fact:
|
2023-11-29 22:24:57 +01:00
|
|
|
reboot:
|
2023-10-25 22:26:17 +02:00
|
|
|
- "{{ item.vmid }}"
|
|
|
|
when: restart.changed
|
|
|
|
|
|
|
|
# Füge die leere Liste "lists_merged" aus den defaults, mit der Liste "reboot" zusammen. Nur wenn auch etwas geändert wurde, daher "when:..."
|
|
|
|
- name: merge reboot lists # noqa no-handler
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
lists_merged: "{{ lists_merged + reboot }}"
|
|
|
|
when: restart.changed
|
|
|
|
# https://blog.crisp.se/2016/10/20/maxwenzin/how-to-append-to-lists-in-ansible
|
|
|
|
|
|
|
|
# - name: debug config
|
|
|
|
# ansible.builtin.debug:
|
|
|
|
# msg: "{{ lists_merged | unique }}"
|
|
|
|
# unique Filter sorgt dafür das es keine doppelten Elemente gibt
|
|
|
|
# https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#set-theory-filters
|
|
|
|
# https://www.reddit.com/r/ansible/comments/8cp86c/how_do_i_remove_duplicate_items_from_a_variable/
|