Skip to content

Commit

Permalink
Drop usage of ipaddr filters and remove dependency on python-netaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
michalskrivanek committed Mar 24, 2023
1 parent 07b5897 commit fd20e99
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Requirements

* Ansible core version 2.12.0 or higher
* Python SDK version 4.5.0 or higher
* Python netaddr library on the ansible controller node

Upstream oVirt documentation
--------------
Expand Down
1 change: 0 additions & 1 deletion README.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Requirements

* Ansible core version 2.12.0 or higher
* Python SDK version 4.5.0 or higher
* Python netaddr library on the ansible controller node

Content of the collection
----------------
Expand Down
3 changes: 3 additions & 0 deletions changelogs/fragments/696-drop-netaddr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- HE - drop usage of ipaddr filters and remove dependency on python-netaddr (https:/oVirt/ovirt-ansible-collection/pull/696)
2 changes: 0 additions & 2 deletions ovirt-ansible-collection.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ Requires: qemu-img
%if 0%{?rhel} >= 9
Requires: python3.11-ovirt-imageio-client
Requires: python3.11-ovirt-engine-sdk4 >= 4.5.0
Requires: python3.11-netaddr
Requires: python3.11-jmespath
Requires: python3.11-passlib
%endif

%if 0%{?rhel} < 9
Requires: python39-ovirt-imageio-client
Requires: python39-ovirt-engine-sdk4 >= 4.5.0
Requires: python39-netaddr
Requires: python39-jmespath
Requires: python39-passlib
%endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@
ansible.builtin.set_fact:
virbr_cidr_ipv4: >-
{{ (hostvars[inventory_hostname]['ansible_'+virbr_default]['ipv4']['address']+'/'
+hostvars[inventory_hostname]['ansible_'+virbr_default]['ipv4']['netmask']) |ipv4('host/prefix') }}
+hostvars[inventory_hostname]['ansible_'+virbr_default]['ipv4']['netmask']) }}
when: not ipv6_deployment|bool
- name: Fetch IPv6 CIDR for {{ virbr_default }}
ansible.builtin.set_fact:
virbr_cidr_ipv6: >-
{{ (hostvars[inventory_hostname]['ansible_'+virbr_default]['ipv6'][0]['address']+'/'+
hostvars[inventory_hostname]['ansible_'+virbr_default]['ipv6'][0]['prefix']) |
ipv6('host/prefix') if 'ipv6' in hostvars[inventory_hostname]['ansible_'+virbr_default] else None }}
hostvars[inventory_hostname]['ansible_'+virbr_default]['ipv6'][0]['prefix'])
if 'ipv6' in hostvars[inventory_hostname]['ansible_'+virbr_default] else None }}
when: ipv6_deployment|bool
- name: Add IPv4 outbound route rules
ansible.builtin.command: ip rule add from {{ virbr_cidr_ipv4 }} priority 101 table main
Expand All @@ -71,7 +71,7 @@
not ipv6_deployment|bool and
route_rules_ipv4.stdout | from_json |
selectattr('priority', 'equalto', 101) |
selectattr('src', 'equalto', virbr_cidr_ipv4 | ipaddr('address') ) |
selectattr('src', 'equalto', virbr_cidr_ipv4) |
list | length == 0
changed_when: true
- name: Add IPv4 inbound route rules
Expand All @@ -83,7 +83,7 @@
not ipv6_deployment|bool and
route_rules_ipv4.stdout | from_json |
selectattr('priority', 'equalto', 100) |
selectattr('dst', 'equalto', virbr_cidr_ipv4 | ipaddr('address') ) |
selectattr('dst', 'equalto', virbr_cidr_ipv4) |
list | length == 0
- name: Add IPv6 outbound route rules
ansible.builtin.command: ip -6 rule add from {{ virbr_cidr_ipv6 }} priority 101 table main
Expand Down
12 changes: 7 additions & 5 deletions roles/hosted_engine_setup/tasks/fetch_host_ip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
- name: Choose IPv4, IPv6 or auto
import_tasks: ipv_switch.yml
- name: Get host address resolution
ansible.builtin.shell: getent {{ ip_key }} {{ he_host_address }} | grep STREAM
ansible.builtin.shell: getent {{ ip_key }} {{ he_host_address }} | grep STREAM | cut -d ' ' -f1
register: hostname_resolution_output
changed_when: true
ignore_errors: true
- name: Get host IP addresses
ansible.builtin.command: hostname -I
register: hostname_addresses_output
changed_when: true
- name: Check address resolution
ansible.builtin.fail:
msg: >
Expand All @@ -29,10 +33,8 @@
ansible.builtin.set_fact:
he_host_ip: "{{
(
hostname_resolution_output.stdout.split() | ipaddr |
difference(hostname_resolution_output.stdout.split() |
ipaddr('link-local')
)
hostname_resolution_output.stdout.split() |
intersect(hostname_addresses_output.stdout.split())
)[0]
}}"
- name: Fail if host's ip is empty
Expand Down

0 comments on commit fd20e99

Please sign in to comment.