Skip to content

Commit

Permalink
HE: Filter IP addresses based on 'ipv6_deployment'
Browse files Browse the repository at this point in the history
At the beginning of HE deployment we set the 'ipv6_deployment' fact
based on host's address. This var should be the source of truth for
whether to use an IPv4 or IPv6 address for the HE VM.

Until now we were simply picking up the first address that was reported
by 'virsh' and using this throughout the rest of the process.

This PR adds filtering of the reported addresses based on the value of
'ipv6_deployment'. Additionally we're picking the first address to make
other usages of 'local_vm_ip' nicer.

Signed-off-by: Marcin Sobczyk <[email protected]>
  • Loading branch information
tinez committed Jul 11, 2022
1 parent 33d273e commit 1559bb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion roles/hosted_engine_setup/tasks/restore_backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1559bb1

Please sign in to comment.