ansible/roles/kvm_install/tasks/hosts_vm2ip.yml

31 lines
970 B
YAML

---
- name: Ensure VM is running, otherwise arp based retrieval of ipv4 address will fail
community.libvirt.virt:
name: "{{ vm_name }}"
state: running
# Starten der vm reicht nicht, das Netzwerk muss auch oben sein um per arp auf die ipv4-Adresse zu kommen
- name: Retrieve ipv4-address for resolution in /etc/hosts on wirt machine
shell: /home/core/Scripte/vhost_getIPv4 "{{ vm_name }}"
register: ipv4
until: ipv4["stdout"] | length > 0
retries: 15
delay: 2
changed_when: "False"
- name: Debug ipv4-address for resolution to /etc/hosts on wirt machine
debug: msg={{ ipv4["stdout"] }}
changed_when: "False"
# hosts-Eintrag nur erzeugen falls die ip ermittelt werden konnte
- name: Write vmname and ipv4-address for resolution to /etc/hosts on wirt machine
ansible.builtin.lineinfile:
path: /etc/hosts
regexp: '^{{ ipv4["stdout"] }} ='
line: "{{ ipv4['stdout'] + ' ' + vm_name }}"
when: ipv4["stdout"] | length > 0
...