mg
12884074ba
Co-authored-by: Michael Grote <michael.grote@posteo.de> Reviewed-on: mg/ansible#285 Co-authored-by: mg <michael.grote@posteo.de> Co-committed-by: mg <michael.grote@posteo.de>
46 lines
1.6 KiB
YAML
46 lines
1.6 KiB
YAML
---
|
|
- 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 }}"
|
|
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
|
|
set_fact:
|
|
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
|
|
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/
|