mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 02:15:17 +00:00
The dependency on `ansible.utils.update_fact` is causing issue with
some users who now must install that collection in order to run
the role, even if they do not care about ostree.
The fix is to stop trying to set `ansible_facts.pkg_mgr`, and instead
force the use of the ostree package manager with the `package:` module
`use:` option. The strategy is - on ostree systems, set the flag
`__$ROLENAME_is_ostree` if the system is an ostree system. The flag
will either be undefined or `false` on non-ostree systems.
Then, change every invocation of the `package:` module like this:
```yaml
- name: Ensure required packages are present
package:
name: "{{ __$ROLENAME_packages }}"
state: present
use: "{{ (__$ROLENAME_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
```
This should ensure that the `use:` parameter is not used if the system
is non-ostree. The goal is to make the ostree support as unobtrusive
as possible for non-ostree systems.
The user can also set `__$ROLENAME_is_ostree: true` in the inventory or play
if the user knows that ostree is being used and wants to skip the check.
Or, the user is concerned about the performance hit for ostree detection
on non-ostree systems, and sets `__$ROLENAME_is_ostree: false` to skip
the check.
The flag `__$ROLENAME_is_ostree` can also be used in the role or tests to
include or exclude tasks from being run on ostree systems.
This fix also improves error reporting in the `get_ostree_data.sh` script
when included roles cannot be found.
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
|
|
---
|
|
- 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"]
|
|
|
|
- name: Include the task 'show_interfaces.yml'
|
|
include_tasks: show_interfaces.yml
|
|
|
|
- name: Install iproute
|
|
package:
|
|
name: iproute
|
|
state: present
|
|
use: "{{ (__network_is_ostree | d(false)) |
|
|
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
|
|
|
|
# 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"
|
|
changed_when: false
|
|
- 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: true # noqa ignore-errors
|
|
when: "type == 'veth' and state == 'present'"
|
|
changed_when: false
|
|
|
|
- name: Delete veth interface {{ interface }}
|
|
command: ip link del {{ interface }} type veth
|
|
when: "type == 'veth' and state == 'absent' and
|
|
interface in current_interfaces"
|
|
changed_when: false
|
|
|
|
# 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"
|
|
changed_when: false
|
|
|
|
- name: Delete dummy interface {{ interface }}
|
|
command: ip link del "{{ interface }}" type dummy
|
|
when: "type == 'dummy' and state == 'absent' and
|
|
interface in current_interfaces"
|
|
changed_when: false
|
|
|
|
# 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"
|
|
changed_when: false
|
|
|
|
- name: Delete tap interface {{ interface }}
|
|
command: ip tuntap del dev {{ interface }} mode tap
|
|
when: "type == 'tap' and state == 'absent' and
|
|
interface in current_interfaces"
|
|
changed_when: false
|