homeserver/roles/mgrote_proxmox_bind_mounts/tasks/bm.yml
Michael Grote ce7100d624
All checks were successful
ansible-lint / gitleaks (pull_request) Successful in 3s
ansible-lint / Ansible Lint (pull_request) Successful in 33s
dd
2024-10-04 14:12:35 +02:00

52 lines
1.9 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
changed_when:
- restart.rc == 25
failed_when:
- (restart.rc != 25) or (restart.rc == 0)
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:
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/