Install NetworkManager-team package when team profiles are configured

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2020-09-14 22:26:06 -04:00 committed by Fernando Fernández Mancera
parent ed5fa4c606
commit c7af145a9a
7 changed files with 120 additions and 3 deletions

View file

@ -35,6 +35,15 @@ __network_packages_default_wireless: ["{%
if __network_wireless_connections_defined
%}NetworkManager-wifi{% endif %}"]
# check if any team connections are defined
__network_team_connections_defined: "{{
['team'] in network_connections|json_query('[*][type]') }}"
# NetworkManager-team is required for team connections
__network_packages_default_team: ["{%
if __network_team_connections_defined
%}NetworkManager-team{% endif %}"]
# wpa_supplicant is required if any 802.1x or wireless connections are defined
__network_wpa_supplicant_required: "{{
__network_ieee802_1x_connections_defined or
@ -54,7 +63,8 @@ __network_service_name_default_nm: NetworkManager
__network_packages_default_nm: "{{['NetworkManager']
+ __network_packages_default_gobject_packages|select()|list()
+ __network_packages_default_wpa_supplicant|select()|list()
+ __network_packages_default_wireless|select()|list()}}"
+ __network_packages_default_wireless|select()|list()
+ __network_packages_default_team|select()|list()}}"
__network_service_name_default_initscripts: network

33
examples/team_simple.yml Normal file
View file

@ -0,0 +1,33 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- hosts: network-test
vars:
network_connections:
# Specify the team profile
- name: team0
state: up
type: team
interface_name: team0
# ip configuration (optional)
ip:
address:
- "192.0.2.24/24"
- "2001:db8::23/64"
# add an team profile to the team
- name: member1
state: up
type: ethernet
interface_name: eth1
master: team0
# add a second team profile to the team
- name: member2
state: up
type: ethernet
interface_name: eth2
master: team0
roles:
- linux-system-roles.network
...

View file

@ -25,14 +25,15 @@
- not network_packages is subset(ansible_facts.packages.keys())
register: __network_package_install
# If network packages have changed and wireless connections are required,
# If network packages changed and wireless or team connections are specified,
# NetworkManager must be restarted
- name: Restart NetworkManager
- name: Restart NetworkManager due to wireless or team interfaces
service:
name: NetworkManager
state: restarted
when:
- __network_wireless_connections_defined
or __network_team_connections_defined
- network_provider == "nm"
- network_allow_restart
# ansible-lint wants this to be a handler, but this is not appropriate as

View file

@ -72,6 +72,10 @@ NM_ONLY_TESTS = {
"comment": "# NetworKmanager 1.20.0 added support for forgetting profiles",
},
"playbooks/tests_reapply.yml": {},
# team interface is not supported on Fedora
"playbooks/tests_team.yml": {
EXTRA_RUN_CONDITION: "ansible_distribution != 'Fedora'",
},
# mac80211_hwsim (used for tests_wireless) only seems to be available
# and working on RHEL/CentOS 7
"playbooks/tests_wireless.yml": {

View file

@ -0,0 +1,30 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- hosts: all
vars:
interface: team0
profile: "{{ interface }}"
lsr_fail_debug:
- __network_connections_result
tasks:
- debug:
msg: "this is: playbooks/tests_team.yml"
tags:
- always
- block:
- include_tasks: tasks/run_test.yml
vars:
lsr_description: Create a team interface without any port attached
lsr_setup:
- tasks/delete_interface.yml
- tasks/assert_device_absent.yml
lsr_test:
- tasks/create_team_profile.yml
lsr_assert:
- tasks/assert_profile_present.yml
- tasks/assert_device_present.yml
lsr_cleanup:
- tasks/cleanup_profile+device.yml
tags:
- tests::team:create

View file

@ -0,0 +1,15 @@
# SPDX-License-Identifier: BSD-3-Clause
---
- include_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
persistent_state: present
type: team
ip:
dhcp4: false
auto6: false
- debug:
var: __network_connections_result
...

24
tests/tests_team_nm.yml Normal file
View file

@ -0,0 +1,24 @@
# SPDX-License-Identifier: BSD-3-Clause
# This file was generated by ensure_provider_tests.py
---
# set network provider and gather facts
- hosts: all
name: Run playbook 'playbooks/tests_team.yml' with nm as provider
tasks:
- name: Set network provider to 'nm'
set_fact:
network_provider: nm
tags:
- always
# workaround for: https://github.com/ansible/ansible/issues/27973
# There is no way in Ansible to abort a playbook hosts with specific OS
# releases Therefore we include the playbook with the tests only if the hosts
# would support it.
# The test requires or should run with NetworkManager, therefore it cannot run
# on RHEL/CentOS 6
- import_playbook: playbooks/tests_team.yml
when:
- ansible_distribution_major_version != '6'
- ansible_distribution != 'Fedora'