49 lines
1.8 KiB
YAML
49 lines
1.8 KiB
YAML
|
---
|
||
|
- 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
|
||
|
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:
|
||
|
ansible.builtin.reboot:
|
||
|
- "{{ 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/
|