network/tests/tasks/manage_test_interface.yml
Rich Megginson db10fc2035 add support for ansible-core 2.11 ansible-lint, ansible-test
Add support for using latest ansible-lint and ansible-test with
ansible-core 2.11.  There are a few new warnings that need to
be addressed or suppressed.

One of the changes is to add `# noqa ignore-errors` to the places in
the role where `ignore_errors: true` is used.  In general, it is not
a good idea to use `ignore_errors: true` - instead, it is better to
capture the result of the command using a `register`, then use
`failed_when`.  Or, if that is not possible, use a `block`/`rescue`
for more complex error handling.  However, in the case where the network
role is using `ignore_errors: true` in test code, it is acceptable.
see https://ansible-lint.readthedocs.io/en/latest/default_rules.html#ignore-errors

Another change is to have all tasks have a valid `name:`.  This
is explained at https://ansible-lint.readthedocs.io/en/latest/default_rules.html#unnamed-task

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-10-11 12:03:00 -06:00

61 lines
2 KiB
YAML

# SPDX-License-Identifier: BSD-3-Clause
---
- name: Ensure state in ["present", "absent"]
fail:
msg: "state needs to be present or absent, not '{{ state }}'"
when: state not in ["present", "absent"]
- name: Ensure type in ["dummy", "tap", "veth"]
fail:
msg: "type needs to be dummy, tap or veth, not '{{ type }}'"
when: type not in ["dummy", "tap", "veth"]
- include: show_interfaces.yml
- name: Install iproute
package:
name: iproute
state: present
# veth
- name: Create veth interface {{ interface }}
command: "{{ item }}"
with_items:
- ip link add {{ interface }} type veth peer name peer{{ interface }}
- ip link set peer{{ interface }} up
- ip link set {{ interface }} up
when: "type == 'veth' and state == 'present' and
interface not in current_interfaces"
- name: Set up veth as managed by NetworkManager
command: nmcli d set {{ interface }} managed true
# The varible for `network_provider` is not exists yet,
# just ignore error for initscripts
ignore_errors: yes # noqa ignore-errors
when: "type == 'veth' and state == 'present'"
- name: Delete veth interface {{ interface }}
command: ip link del {{ interface }} type veth
when: "type == 'veth' and state == 'absent' and
interface in current_interfaces"
# dummy
- name: Create dummy interface {{ interface }}
command: ip link add "{{ interface }}" type dummy
when: "type == 'dummy' and state == 'present' and
interface not in current_interfaces"
- name: Delete dummy interface {{ interface }}
command: ip link del "{{ interface }}" type dummy
when: "type == 'dummy' and state == 'absent' and
interface in current_interfaces"
# tap
- name: Create tap interface {{ interface }}
command: ip tuntap add dev {{ interface }} mode tap
when: "type == 'tap' and state == 'present'
and interface not in current_interfaces"
- name: Delete tap interface {{ interface }}
command: ip tuntap del dev {{ interface }} mode tap
when: "type == 'tap' and state == 'absent' and
interface in current_interfaces"