mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-23 19:07:45 +00:00
The role gathers the facts it uses. For example, if the user uses `ANSIBLE_GATHERING=explicit`, the role uses the `setup` module with the facts and subsets it requires. This change allows us to test this. Before every role invocation, the test will use `meta: clear_facts` so that the role starts with no facts. Create a task file tests/tasks/run_role_with_clear_facts.yml to do the tasks to clear the facts and run the role. Note that this means we don't need to use `gather_facts` for the tests. Some vars defined using `ansible_facts` have been changed to be defined with `set_fact` instead. This is because of the fact that `vars` are lazily evaluated - the var might be referenced when the facts have been cleared, and will issue an error like `ansible_facts["distribution"] is undefined`. This is typically done for blocks that have a `when` condition that uses `ansible_facts` and the block has a role invocation using run_role_with_clear_facts.yml These have been rewritten to define the `when` condition using `set_fact`. This is because the `when` condition is evaluated every time a task is invoked in the block, and if the facts are cleared, this will raise an undefined variable error. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
71 lines
2.3 KiB
YAML
71 lines
2.3 KiB
YAML
# SPDX-License-Identifier: BSD-3-Clause
|
|
# This file was generated by ensure_provider_tests.py
|
|
---
|
|
# set network provider and gather facts
|
|
- name: Switch initscripts provider to nm
|
|
hosts: all
|
|
vars:
|
|
network_provider: initscripts
|
|
interface: LST-TST-br34
|
|
tasks:
|
|
- name: "Through the initscripts provider, create test bridge
|
|
{{ interface }}"
|
|
include_tasks: tasks/run_role_with_clear_facts.yml
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface }}"
|
|
state: up
|
|
type: bridge
|
|
ip:
|
|
dhcp4: false
|
|
auto6: false
|
|
|
|
- name: Include the task 'assert_device_present.yml'
|
|
include_tasks: tasks/assert_device_present.yml
|
|
|
|
- name: Include the task 'remove+down_profile.yml'
|
|
include_tasks: tasks/remove+down_profile.yml
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
# The initscripts should not remove the interface for down/absent
|
|
|
|
- name: Include the task 'assert_device_present.yml' with new profile
|
|
include_tasks: tasks/assert_device_present.yml
|
|
|
|
- name: Set fact to use nm network_provider
|
|
set_fact:
|
|
network_provider: nm
|
|
tags:
|
|
- always
|
|
|
|
- name: "Through the nm provider, create test bridge {{ interface }}"
|
|
include_tasks: tasks/run_role_with_clear_facts.yml
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface }}"
|
|
state: up
|
|
type: bridge
|
|
ip:
|
|
dhcp4: false
|
|
auto6: false
|
|
|
|
- name: Include the task 'assert_device_present.yml' with nm provider
|
|
include_tasks: tasks/assert_device_present.yml
|
|
|
|
- name: Include the task 'remove+down_profile.yml' with nm provider
|
|
include_tasks: tasks/remove+down_profile.yml
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
|
|
# NetworkManager should not remove pre-exist interface for down/absent
|
|
- name: Include the task 'assert_device_present.yml' with nm provider again
|
|
include_tasks: tasks/assert_device_present.yml
|
|
|
|
- name: Include the task 'delete_interface.yml'
|
|
include_tasks: tasks/delete_interface.yml
|
|
|
|
- name: Include the task 'assert_device_absent.yml'
|
|
include_tasks: tasks/assert_device_absent.yml
|
|
|
|
- name: Verify network state restored to default
|
|
include_tasks: tasks/check_network_dns.yml
|