Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HE: Filter IP addresses based on 'ipv6_deployment' #560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/560-he-filter-ip-addresses.yml
Original file line number Diff line number Diff line change
@@ -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)
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 }}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible.netcommon, is this a new collection?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, no, we already depend on it. Thouhg it looks unused until now

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