diff --git a/changelogs/fragments/560-he-filter-ip-addresses.yml b/changelogs/fragments/560-he-filter-ip-addresses.yml new file mode 100644 index 00000000..0a6a0cb5 --- /dev/null +++ b/changelogs/fragments/560-he-filter-ip-addresses.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - HE - Use ipv6_deployment var to select appropriate addresses for the HE VM (https://github.com/oVirt/ovirt-ansible-collection/pull/560) diff --git a/roles/hosted_engine_setup/tasks/bootstrap_local_vm/02_create_local_vm.yml b/roles/hosted_engine_setup/tasks/bootstrap_local_vm/02_create_local_vm.yml index 9b8aec3a..5689d663 100644 --- a/roles/hosted_engine_setup/tasks/bootstrap_local_vm/02_create_local_vm.yml +++ b/roles/hosted_engine_setup/tasks/bootstrap_local_vm/02_create_local_vm.yml @@ -117,14 +117,22 @@ - name: Get local VM IP ansible.builtin.shell: virsh -r net-dhcp-leases default | grep -i {{ he_vm_mac_addr }} | awk '{ print $5 }' | cut -f1 -d'/' environment: "{{ he_cmd_lang }}" - register: local_vm_ip - until: local_vm_ip.stdout_lines|length >= 1 + register: local_vm_ip_candidates + until: local_vm_ip_candidates.stdout_lines|length >= 1 retries: 90 delay: 10 changed_when: true - - name: Debug var local_vm_ip + - name: Debug var local_vm_ip_candidates ansible.builtin.debug: - var: local_vm_ip + var: local_vm_ip_candidates + - name: Select first IPv6 address + ansible.builtin.set_fact: + local_vm_ip: "{{ local_vm_ip_candidates.stdout_lines | ansible.netcommon.ipv6 | first }}" + when: ipv6_deployment + - name: Select first IPv4 address + ansible.builtin.set_fact: + local_vm_ip: "{{ local_vm_ip_candidates.stdout_lines | ansible.netcommon.ipv4 | first }}" + when: not ipv6_deployment - name: Remove leftover entries in /etc/hosts for the local VM ansible.builtin.lineinfile: dest: /etc/hosts @@ -134,7 +142,7 @@ ansible.builtin.lineinfile: dest: /etc/hosts line: - "{{ local_vm_ip.stdout_lines[0] }} \ + "{{ local_vm_ip }} \ {{ he_fqdn }} # temporary entry added by hosted-engine-setup for the bootstrap VM" insertbefore: BOF backup: true @@ -146,7 +154,7 @@ timeout=300 - name: Set the name for add_host ansible.builtin.set_fact: - he_fqdn_ansible_host: "{{ local_vm_ip.stdout_lines[0] }}" + he_fqdn_ansible_host: "{{ local_vm_ip }}" - import_tasks: ../add_engine_as_ansible_host.yml rescue: - include_tasks: ../clean_localvm_dir.yml diff --git a/roles/hosted_engine_setup/tasks/bootstrap_local_vm/03_engine_initial_tasks.yml b/roles/hosted_engine_setup/tasks/bootstrap_local_vm/03_engine_initial_tasks.yml index 775acb1d..17f17851 100644 --- a/roles/hosted_engine_setup/tasks/bootstrap_local_vm/03_engine_initial_tasks.yml +++ b/roles/hosted_engine_setup/tasks/bootstrap_local_vm/03_engine_initial_tasks.yml @@ -18,7 +18,7 @@ ansible.builtin.lineinfile: path: /etc/hosts line: - "{{ hostvars[he_ansible_host_name]['local_vm_ip']['stdout_lines'][0] }} {{ he_fqdn }} # hosted-engine-setup-{{ \ + "{{ hostvars[he_ansible_host_name]['local_vm_ip'] }} {{ he_fqdn }} # hosted-engine-setup-{{ \ hostvars[he_ansible_host_name]['he_local_vm_dir'] }}" - name: Reconfigure IPv6 default gateway ansible.builtin.command: ip -6 route add default via "{{ he_ipv6_subnet_prefix + '::1' }}" @@ -99,7 +99,7 @@ ansible.builtin.debug: msg: >- You can now connect from this host to the bootstrap engine VM using ssh as root - and the temporary IP address - {{ hostvars[he_ansible_host_name]['local_vm_ip']['stdout_lines'][0] }} + and the temporary IP address - {{ hostvars[he_ansible_host_name]['local_vm_ip'] }} - include_tasks: ../pause_execution.yml when: he_pause_before_engine_setup|bool - name: Restore a backup diff --git a/roles/hosted_engine_setup/tasks/create_target_vm/01_create_target_hosted_engine_vm.yml b/roles/hosted_engine_setup/tasks/create_target_vm/01_create_target_hosted_engine_vm.yml index 16bcd521..6f704dd2 100644 --- a/roles/hosted_engine_setup/tasks/create_target_vm/01_create_target_hosted_engine_vm.yml +++ b/roles/hosted_engine_setup/tasks/create_target_vm/01_create_target_hosted_engine_vm.yml @@ -5,11 +5,19 @@ - name: Get local VM IP ansible.builtin.shell: virsh -r net-dhcp-leases default | grep -i {{ he_vm_mac_addr }} | awk '{ print $5 }' | cut -f1 -d'/' environment: "{{ he_cmd_lang }}" - register: local_vm_ip + register: local_vm_ip_candidates changed_when: true + - name: Select first IPv6 address + ansible.builtin.set_fact: + local_vm_ip: "{{ local_vm_ip_candidates.stdout_lines | ansible.netcommon.ipv6 | first }}" + when: ipv6_deployment + - name: Select first IPv4 address + ansible.builtin.set_fact: + local_vm_ip: "{{ local_vm_ip_candidates.stdout_lines | ansible.netcommon.ipv4 | first }}" + when: not ipv6_deployment - name: Set the name for add_host ansible.builtin.set_fact: - he_fqdn_ansible_host: "{{ local_vm_ip.stdout_lines[0] }}" + he_fqdn_ansible_host: "{{ local_vm_ip }}" - import_tasks: ../add_engine_as_ansible_host.yml - name: Fetch host facts ovirt_host_info: diff --git a/roles/hosted_engine_setup/tasks/restore_backup.yml b/roles/hosted_engine_setup/tasks/restore_backup.yml index 97cf737e..96f75700 100644 --- a/roles/hosted_engine_setup/tasks/restore_backup.yml +++ b/roles/hosted_engine_setup/tasks/restore_backup.yml @@ -26,7 +26,7 @@ You can now connect from this host to the bootstrap engine VM using ssh as root and the temporary IP address - - {{ hostvars[he_ansible_host_name]['local_vm_ip']['stdout_lines'][0] }} - + {{ hostvars[he_ansible_host_name]['local_vm_ip'] }} - and fix this issue. Please continue only after the backup is restored. To retry the command that failed, you can run, on the bootstrap engine VM: