mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-26 12:24:00 +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>
138 lines
4.2 KiB
YAML
138 lines
4.2 KiB
YAML
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
- name: Play for testing dns support
|
|
hosts: all
|
|
vars:
|
|
type: veth
|
|
interface: ethtest0
|
|
tasks:
|
|
- name: Include the task 'show_interfaces.yml'
|
|
include_tasks: tasks/show_interfaces.yml
|
|
|
|
- name: Include the task 'manage_test_interface.yml'
|
|
include_tasks: tasks/manage_test_interface.yml
|
|
vars:
|
|
state: present
|
|
|
|
- name: Include the task 'assert_device_present.yml'
|
|
include_tasks: tasks/assert_device_present.yml
|
|
|
|
- name: Include network role
|
|
include_tasks: tasks/run_role_with_clear_facts.yml
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface }}"
|
|
interface_name: "{{ interface }}"
|
|
state: up
|
|
type: ethernet
|
|
autoconnect: true
|
|
ip:
|
|
route_metric4: 100
|
|
dhcp4: false
|
|
gateway4: 192.0.2.1
|
|
dns_priority: 9999
|
|
dns:
|
|
- 192.0.2.2
|
|
- 198.51.100.5
|
|
- 2001:db8::20
|
|
dns_search:
|
|
- example.com
|
|
- example.org
|
|
dns_options:
|
|
- no-aaaa
|
|
- rotate
|
|
- timeout:1
|
|
|
|
route_metric6: -1
|
|
auto6: false
|
|
gateway6: 2001:db8::1
|
|
|
|
address:
|
|
- 192.0.2.3/24
|
|
- 198.51.100.3/26
|
|
- 2001:db8::80/7
|
|
|
|
route:
|
|
- network: 198.51.100.128
|
|
prefix: 26
|
|
gateway: 198.51.100.1
|
|
metric: 2
|
|
- network: 198.51.100.64
|
|
prefix: 26
|
|
gateway: 198.51.100.6
|
|
metric: 4
|
|
route_append_only: false
|
|
rule_append_only: true
|
|
|
|
- name: Verify nmcli connection DNS entry for IPv4
|
|
shell: |
|
|
set -euxo pipefail
|
|
nmcli connection show {{ interface }} | grep ipv4.dns
|
|
register: ipv4_dns
|
|
ignore_errors: true
|
|
changed_when: false
|
|
|
|
- name: Verify nmcli connection DNS entry for IPv6
|
|
shell: |
|
|
set -euxo pipefail
|
|
nmcli connection show {{ interface }} | grep ipv6.dns
|
|
register: ipv6_dns
|
|
ignore_errors: true
|
|
changed_when: false
|
|
|
|
- name: "Assert that DNS addresses are configured correctly"
|
|
assert:
|
|
that:
|
|
- "'192.0.2.2' in ipv4_dns.stdout"
|
|
- "'198.51.100.5' in ipv4_dns.stdout"
|
|
- "'2001:db8::20' in ipv6_dns.stdout"
|
|
msg: "DNS addresses are configured incorrectly"
|
|
|
|
- name: "Assert that DNS search domains are configured correctly"
|
|
assert:
|
|
that:
|
|
- "'example.com' in ipv4_dns.stdout"
|
|
- "'example.org' in ipv4_dns.stdout"
|
|
- "'example.com' in ipv6_dns.stdout"
|
|
- "'example.org' in ipv6_dns.stdout"
|
|
msg: "DNS search domains are configured incorrectly"
|
|
|
|
- name: "Assert that DNS options are configured correctly"
|
|
assert:
|
|
that:
|
|
- "'no-aaaa' in ipv4_dns.stdout"
|
|
- "'rotate' in ipv4_dns.stdout"
|
|
- "'timeout:1' in ipv4_dns.stdout"
|
|
- "'no-aaaa' in ipv6_dns.stdout"
|
|
- "'rotate' in ipv6_dns.stdout"
|
|
- "'timeout:1' in ipv6_dns.stdout"
|
|
msg: "DNS options are configured incorrectly"
|
|
|
|
- name: "Assert that DNS priority is configured correctly"
|
|
assert:
|
|
that:
|
|
- "'9999' in ipv4_dns.stdout"
|
|
- "'9999' in ipv6_dns.stdout"
|
|
msg: "DNS priority is configured incorrectly"
|
|
|
|
- name: Include the tasks 'down_profile+delete_interface.yml'
|
|
include_tasks: tasks/down_profile+delete_interface.yml
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
|
|
# FIXME: assert profile/device down
|
|
- name: Include the task 'remove_profile.yml'
|
|
include_tasks: tasks/remove_profile.yml
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
|
|
- name: Include the task 'assert_profile_absent.yml'
|
|
include_tasks: tasks/assert_profile_absent.yml
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
|
|
- 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
|