2021-10-10 16:47:36 +02:00
|
|
|
---
|
|
|
|
- name: read config
|
|
|
|
become: true
|
|
|
|
shell: "pct config {{ item.vmid }} | grep \"mp{{ item.mp_nr }}: {{ item.mp_path_host }},mp={{ item.mp_path_guest }}\""
|
|
|
|
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
|
|
|
|
become: true
|
|
|
|
command: "pct set {{ item.vmid }} -mp{{ item.mp_nr }} {{ item.mp_path_host }},mp={{ item.mp_path_guest }}"
|
|
|
|
when: not config.rc == 0
|
|
|
|
register: restart
|
|
|
|
notify: restart lxc
|
|
|
|
# füge bind-mount hinzu falls er fehlt, also rc ungleich 0
|
|
|
|
# pro bind-mount
|
|
|
|
|
2021-10-13 12:20:26 +02:00
|
|
|
# schreibe vm id in die Liste "reboot"
|
|
|
|
- name: set reboot list
|
2021-10-10 16:47:36 +02:00
|
|
|
set_fact:
|
2021-10-13 12:20:26 +02:00
|
|
|
reboot:
|
|
|
|
- "{{ item.vmid }}"
|
2021-10-10 16:47:36 +02:00
|
|
|
when: restart.changed
|
2021-10-13 12:20:26 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
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/
|