Skip to content
Merged
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
22 changes: 11 additions & 11 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ __network_rh_distros:
__network_rh_distros_fedora: "{{ __network_rh_distros + ['Fedora'] }}"

# Use this in conditionals to check if distro is Red Hat or clone
__network_is_rh_distro: "{{ ansible_distribution in __network_rh_distros }}"
__network_is_rh_distro: "{{ ansible_facts['distribution'] in __network_rh_distros }}"

# Use this in conditionals to check if distro is Red Hat or clone, or Fedora
__network_is_rh_distro_fedora: "{{ ansible_distribution in __network_rh_distros_fedora }}"
__network_is_rh_distro_fedora: "{{ ansible_facts['distribution'] in __network_rh_distros_fedora }}"
# END - DO NOT EDIT THIS BLOCK - rh distros variables

# Use initscripts for RHEL/CentOS < 7, nm otherwise
network_provider_os_default: "{{
'initscripts' if ansible_distribution in __network_rh_distros and
ansible_distribution_major_version is version('7', '<')
'initscripts' if ansible_facts['distribution'] in __network_rh_distros and
ansible_facts['distribution_major_version'] is version('7', '<')
else 'nm' }}"
# If NetworkManager.service is running, assume that 'nm' is currently in-use,
# otherwise initscripts
Expand Down Expand Up @@ -76,7 +76,7 @@ __network_packages_default_wpa_supplicant: ["{%
# - python-gobject-base on RHEL7 (no python2-gobject-base :-/)
# - python3-gobject-base on Fedora 28+
__network_packages_default_gobject_packages: ["python{{
ansible_python['version']['major'] | replace('2', '') }}-gobject-base"]
ansible_facts['python']['version']['major'] | replace('2', '') }}-gobject-base"]

__network_service_name_default_nm: NetworkManager
__network_packages_default_nm: "{{ ['NetworkManager']
Expand All @@ -92,18 +92,18 @@ __network_service_name_default_initscripts: network
__network_packages_default_initscripts_bridge: ["{%
if network_connections | selectattr('type', 'defined') |
selectattr('type', 'match', '^bridge$') | list | count > 0 and
ansible_distribution in __network_rh_distros and
ansible_distribution_major_version is version('7', '<=')
ansible_facts['distribution'] in __network_rh_distros and
ansible_facts['distribution_major_version'] is version('7', '<=')
%}bridge-utils{% endif %}"]
__network_packages_default_initscripts_network_scripts: ["{%
if ansible_distribution in __network_rh_distros and
ansible_distribution_major_version is version('7', '<=')
if ansible_facts['distribution'] in __network_rh_distros and
ansible_facts['distribution_major_version'] is version('7', '<=')
%}initscripts{% else %}network-scripts{% endif %}"]
# Initscripts provider requires `/sbin/dhclient` to obtain DHCP address,
# which is provided by the dhcp client package
__network_packages_default_initscripts_dhcp_client: ["{%
if ansible_distribution in __network_rh_distros and
ansible_distribution_major_version is version('7', '<=')
if ansible_facts['distribution'] in __network_rh_distros and
ansible_facts['distribution_major_version'] is version('7', '<=')
%}dhclient{% else %}dhcp-client{% endif %}"]
# convert _network_packages_default_initscripts_bridge to an empty list if it
# contains only the empty string and add it to the default package list
Expand Down
30 changes: 15 additions & 15 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
supported since RHEL-8
when:
- network_state != {}
- ansible_distribution_major_version | int < 8
- ansible_facts["distribution_major_version"] | int < 8

- name: Abort applying teaming configuration if the system version
of the managed host is EL10 or later
fail:
msg: >-
Teaming is not supported in
{{ ansible_distribution }}-{{ ansible_distribution_major_version }} -
{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"] }} -
use bonding instead
when:
- ansible_distribution_major_version | int > 9
- ansible_distribution in __network_rh_distros
- ansible_facts["distribution_major_version"] | int > 9
- ansible_facts["distribution"] in __network_rh_distros
- network_connections | selectattr("type", "defined") |
selectattr("type", "match", "^team$") | list | length > 0 or
network_state.get("interfaces", []) | selectattr("type", "defined") |
Expand All @@ -49,8 +49,8 @@
register: dnf_package_update_info
check_mode: true
when:
- ansible_distribution == 'Fedora' or
ansible_distribution_major_version | int > 7
- ansible_facts["distribution"] == 'Fedora' or
ansible_facts["distribution_major_version"] | int > 7
- __network_wireless_connections_defined
or __network_team_connections_defined
- not __network_is_ostree
Expand All @@ -64,7 +64,7 @@
register: yum_package_update_info
check_mode: true
when:
- ansible_distribution_major_version | int < 8
- ansible_facts["distribution_major_version"] | int < 8
- __network_wireless_connections_defined
or __network_team_connections_defined
- not __network_is_ostree
Expand Down Expand Up @@ -112,10 +112,10 @@
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- network_state != {}
- ansible_distribution == 'Fedora' and
ansible_distribution_major_version | int > 27 or
ansible_distribution != 'Fedora' and
ansible_distribution_major_version | int > 7
- ansible_facts["distribution"] == 'Fedora' and
ansible_facts["distribution_major_version"] | int > 27 or
ansible_facts["distribution"] != 'Fedora' and
ansible_facts["distribution_major_version"] | int > 7

- name: Install python3-libnmstate when using network_state variable
package:
Expand All @@ -126,10 +126,10 @@
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- network_state != {}
- ansible_distribution == 'Fedora' and
ansible_distribution_major_version | int > 34 or
ansible_distribution != 'Fedora' and
ansible_distribution_major_version | int > 8
- ansible_facts["distribution"] == 'Fedora' and
ansible_facts["distribution_major_version"] | int > 34 or
ansible_facts["distribution"] != 'Fedora' and
ansible_facts["distribution_major_version"] | int > 8

# If network packages changed and wireless or team connections are specified,
# NetworkManager must be restarted, and the user needs to explicitly consent
Expand Down
48 changes: 23 additions & 25 deletions tests/ensure_provider_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
GET_NM_VERSION = """
- name: Install NetworkManager and get NetworkManager version
when:
- ansible_distribution_major_version != '6'
- ansible_facts['distribution_major_version'] != '6'
tags:
- always
block:
Expand Down Expand Up @@ -58,24 +58,24 @@
{comment}- name: Import the playbook '{test_playbook}'
import_playbook: {test_playbook}
when:
- ansible_distribution_major_version != '6'
- ansible_facts['distribution_major_version'] != '6'
{minimum_nm_version_check}{extra_run_condition}"""

MINIMUM_VERSION = "minimum_version"
EXTRA_RUN_CONDITION = "extra_run_condition"
NM_ONLY_TESTS = {
"playbooks/tests_802_1x_updated.yml": {
EXTRA_RUN_CONDITION: (
"(ansible_distribution != 'RedHat' and\n"
" ansible_distribution_major_version | int > 7) or\n"
" ansible_distribution_major_version | int == 8"
"(ansible_facts['distribution'] != 'RedHat' and\n"
" ansible_facts['distribution_major_version'] | int > 7) or\n"
" ansible_facts['distribution_major_version'] | int == 8"
),
},
"playbooks/tests_802_1x.yml": {
EXTRA_RUN_CONDITION: (
"(ansible_distribution != 'RedHat' and\n"
" ansible_distribution_major_version | int > 7) or\n"
" ansible_distribution_major_version | int == 8"
"(ansible_facts['distribution'] != 'RedHat' and\n"
" ansible_facts['distribution_major_version'] | int > 7) or\n"
" ansible_facts['distribution_major_version'] | int == 8"
),
},
"playbooks/tests_ignore_auto_dns.yml": {},
Expand All @@ -94,18 +94,18 @@
MINIMUM_VERSION: "'1.20.0'",
"comment": "# NetworKmanager 1.20.0 added support for forgetting profiles",
EXTRA_RUN_CONDITION: (
"(ansible_distribution == 'Fedora'\n"
" and ansible_distribution_major_version | int < 41)\n"
" or ansible_distribution not in ['RedHat', 'CentOS', 'Fedora']\n"
" or ansible_distribution_major_version | int < 9"
"(ansible_facts['distribution'] == 'Fedora'\n"
" and ansible_facts['distribution_major_version'] | int < 41)\n"
" or ansible_facts['distribution'] not in ['RedHat', 'CentOS', 'Fedora']\n"
" or ansible_facts['distribution_major_version'] | int < 9"
),
},
"playbooks/tests_eth_pci_address_match.yml": {
MINIMUM_VERSION: "'1.26.0'",
"comment": "# NetworkManager 1.26.0 added support for match.path setting",
},
"playbooks/tests_network_state.yml": {
EXTRA_RUN_CONDITION: "ansible_distribution_major_version | int > 7",
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] | int > 7",
},
"playbooks/tests_reapply.yml": {},
"playbooks/tests_route_table.yml": {},
Expand All @@ -117,32 +117,30 @@
"playbooks/tests_routing_rules.yml": {},
# teaming support dropped in EL10
"playbooks/tests_team.yml": {
EXTRA_RUN_CONDITION: "ansible_distribution not in ['RedHat', 'CentOS'] or\n ansible_distr\
ibution_major_version | int < 10",
EXTRA_RUN_CONDITION: "ansible_facts['distribution'] not in ['RedHat', 'CentOS'] or\n ansible_facts['distribution_major_version'] | int < 10",
},
"playbooks/tests_team_plugin_installation.yml": {
EXTRA_RUN_CONDITION: "ansible_distribution not in ['RedHat', 'CentOS'] or\n ansible_distr\
ibution_major_version | int < 10",
EXTRA_RUN_CONDITION: "ansible_facts['distribution'] not in ['RedHat', 'CentOS'] or\n ansible_facts['distribution_major_version'] | int < 10",
},
# mac80211_hwsim (used for tests_wireless) only seems to be available
# and working on RHEL/CentOS 7
"playbooks/tests_wireless.yml": {
EXTRA_RUN_CONDITION: "ansible_distribution_major_version == '7'",
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] == '7'",
},
"playbooks/tests_wireless_and_network_restart.yml": {},
"playbooks/tests_wireless_plugin_installation.yml": {},
"playbooks/tests_wireless_wpa3_owe.yml": {
"comment": "# OWE has not been supported by NetworkManager 1.18.8 on \
RHEL 7(dist-tag). Failed in setting up mock wifi on RHEL 8",
EXTRA_RUN_CONDITION: "ansible_distribution_major_version > '7' and \
ansible_distribution == 'CentOS' or\n ansible_distribution_major_version > '32' \
and ansible_distribution == 'Fedora'",
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] > '7' and \
ansible_facts['distribution'] == 'CentOS' or\n ansible_facts['distribution_major_version'] > '32' \
and ansible_facts['distribution'] == 'Fedora'",
},
"playbooks/tests_wireless_wpa3_sae.yml": {
"comment": "# SAE has not been supported by NetworkManager 1.18.8 on \
RHEL 7. Failed in setting up mock wifi on RHEL 8",
EXTRA_RUN_CONDITION: "ansible_distribution_major_version != '7' and \
ansible_distribution != 'RedHat'",
EXTRA_RUN_CONDITION: "ansible_facts['distribution_major_version'] != '7' and \
ansible_facts['distribution'] != 'RedHat'",
},
}
# NM_CONDITIONAL_TESTS is used to store the test playbooks which are demanding for NM
Expand Down Expand Up @@ -187,8 +185,8 @@

- name: Import the playbook '{test_playbook}'
import_playbook: {test_playbook}
when: (ansible_distribution in ['CentOS','RedHat'] and\n \
ansible_distribution_major_version | int < 9)
when: (ansible_facts['distribution'] in ['CentOS','RedHat'] and\n \
ansible_facts['distribution_major_version'] | int < 9)
"""


Expand Down
8 changes: 4 additions & 4 deletions tests/playbooks/tests_ethernet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
when:
- network_provider == 'nm'
# RHEL up to 8 uses initscripts backend
- ansible_distribution_major_version | int >= 9
- ansible_facts["distribution_major_version"] | int >= 9

- name: Assert settings in NM connection file
assert:
Expand All @@ -64,7 +64,7 @@
when:
- network_provider == 'nm'
# RHEL up to 8 uses initscripts backend
- ansible_distribution_major_version | int >= 9
- ansible_facts["distribution_major_version"] | int >= 9

- name: Get NM connection status
command: "nmcli connection show {{ interface }}"
Expand All @@ -82,7 +82,7 @@
slurp:
src: "/etc/sysconfig/network-scripts/ifcfg-{{ interface }}"
register: initscripts_connection_file
when: network_provider == 'initscripts' or ansible_distribution_major_version | int < 9
when: network_provider == 'initscripts' or ansible_facts["distribution_major_version"] | int < 9

- name: Assert settings in initscripts connection file
assert:
Expand All @@ -91,7 +91,7 @@
- "'DEVICE={{ interface }}' in initscripts_connection_file.content | b64decode"
- "'IPADDR=192.0.2.1' in initscripts_connection_file.content | b64decode"
- "'PREFIX=24' in initscripts_connection_file.content | b64decode"
when: network_provider == 'initscripts' or ansible_distribution_major_version | int < 9
when: network_provider == 'initscripts' or ansible_facts["distribution_major_version"] | int < 9

- name: Include the tasks 'down_profile+delete_interface.yml'
include_tasks: tasks/down_profile+delete_interface.yml
Expand Down
6 changes: 3 additions & 3 deletions tests/playbooks/tests_ipv6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ip netns exec ns1 ip link set peer{{ interface }} up
when:
# netns not available on RHEL/CentOS 6
- ansible_distribution_major_version != '6'
- ansible_facts['distribution_major_version'] != '6'
changed_when: false
- name: Test IPv6 config
block:
Expand Down Expand Up @@ -87,7 +87,7 @@
- name: Test gateway can be pinged
command: ping6 -c1 2001:db8::1
when:
- ansible_distribution_major_version != '6'
- ansible_facts['distribution_major_version'] != '6'
changed_when: false
always:
- name: "TEARDOWN: remove profiles."
Expand All @@ -109,7 +109,7 @@
- name: Clean up namespace
command: ip netns delete ns1
when:
- ansible_distribution_major_version != '6'
- ansible_facts['distribution_major_version'] != '6'
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
6 changes: 3 additions & 3 deletions tests/playbooks/tests_ipv6_dns_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@
state: up
ignore_errors: true # noqa ignore-errors
changed_when: false
when: ansible_distribution_major_version | int > 7
when: ansible_facts["distribution_major_version"] | int > 7

- name: Assert that reconfiguring network connection is failed
assert:
that:
- __network_connections_result.failed
msg: reconfiguring network connection is not failed
when: ansible_distribution_major_version | int > 7
when: ansible_facts["distribution_major_version"] | int > 7

- name: Assert that configuring DNS search setting is not allowed when
both IPv4 and IPv6 are disabled
Expand All @@ -145,7 +145,7 @@
msg: Reconfiguring network connection is not failed with the error
"Setting 'dns_search', 'dns_options', and 'dns_priority' are not
allowed when both IPv4 and IPv6 are disabled."
when: ansible_distribution_major_version | int > 7
when: ansible_facts["distribution_major_version"] | int > 7

always:
- name: Clean up the test device and the connection profile
Expand Down
Loading
Loading