WIP3
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-interface_stat.yml
|
||||
- name: "assert that interface {{ interface }} is absent"
|
||||
assert:
|
||||
that: not interface_stat.stat.exists
|
||||
msg: "{{ interface }} exists"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-interface_stat.yml
|
||||
- name: "assert that interface {{ interface }} is present"
|
||||
assert:
|
||||
that: interface_stat.stat.exists
|
||||
msg: "{{ interface }} does not exist"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-profile_stat.yml
|
||||
- name: "assert that profile '{{ profile }}' is absent"
|
||||
assert:
|
||||
that: not profile_stat.stat.exists
|
||||
msg: "profile {{ profile_path }} does exist"
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-profile_stat.yml
|
||||
- name: "assert that profile '{{ profile }}' is present"
|
||||
assert:
|
||||
that: profile_stat.stat.exists
|
||||
msg: "profile {{ profile_path }} does not exist"
|
||||
@@ -0,0 +1,20 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_absent.yml
|
||||
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: present
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_present.yml
|
||||
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_absent.yml
|
||||
@@ -0,0 +1,8 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- command: ls -1
|
||||
args:
|
||||
chdir: /sys/class/net
|
||||
register: _current_interfaces
|
||||
- set_fact:
|
||||
current_interfaces: "{{ _current_interfaces.stdout_lines }}"
|
||||
@@ -0,0 +1,9 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: "Get stat for interface {{ interface }}"
|
||||
stat:
|
||||
get_attributes: false
|
||||
get_checksum: false
|
||||
get_mime: false
|
||||
path: "/sys/class/net/{{ interface }}"
|
||||
register: interface_stat
|
||||
@@ -0,0 +1,26 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: "Get stat for network-scripts"
|
||||
stat:
|
||||
get_attributes: false
|
||||
get_checksum: false
|
||||
get_mime: false
|
||||
path: "/etc/sysconfig/network-scripts"
|
||||
register: network_scripts_stat
|
||||
- name: Set profile path (network-scripts)
|
||||
set_fact:
|
||||
profile_path: /etc/sysconfig/network-scripts/ifcfg-{{ profile }}
|
||||
when:
|
||||
- network_scripts_stat.stat.exists
|
||||
- name: Set profile path (NetworkManager system-connections)
|
||||
set_fact:
|
||||
profile_path: /etc/NetworkManager/system-connections/{{ profile }}
|
||||
when:
|
||||
- not network_scripts_stat.stat.exists
|
||||
- name: stat profile file
|
||||
stat:
|
||||
get_attributes: false
|
||||
get_checksum: false
|
||||
get_mime: false
|
||||
path: "{{ profile_path }}"
|
||||
register: profile_stat
|
||||
@@ -0,0 +1,50 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- fail:
|
||||
msg: "state needs to be present or absent, not '{{ state }}'"
|
||||
when: state not in ["present", "absent"]
|
||||
|
||||
- fail:
|
||||
msg: "type needs to be dummy, tap or veth, not '{{ type }}'"
|
||||
when: type not in ["dummy", "tap", "veth"]
|
||||
|
||||
# - include: get-current_interfaces.yml
|
||||
- include: show-interfaces.yml
|
||||
|
||||
- name: Install iproute
|
||||
package:
|
||||
name: iproute
|
||||
state: present
|
||||
|
||||
# veth
|
||||
- name: Create veth interface {{ interface }}
|
||||
shell: ip link add {{ interface }} type veth peer name peer{{ interface }}
|
||||
when: "type == 'veth' and state == 'present' and
|
||||
interface not in current_interfaces"
|
||||
|
||||
- name: Delete veth interface {{ interface }}
|
||||
shell: ip link del {{ interface }} type veth
|
||||
when: "type == 'veth' and state == 'absent' and
|
||||
interface in current_interfaces"
|
||||
|
||||
# dummy
|
||||
- name: Create dummy interface {{ interface }}
|
||||
shell: ip link add "{{ interface }}" type dummy
|
||||
when: "type == 'dummy' and state == 'present' and
|
||||
interface not in current_interfaces"
|
||||
|
||||
- name: Delete dummy interface {{ interface }}
|
||||
shell: ip link del "{{ interface }}" type dummy
|
||||
when: "type == 'dummy' and state == 'absent' and
|
||||
interface in current_interfaces"
|
||||
|
||||
# tap
|
||||
- name: Create tap interface {{ interface }}
|
||||
shell: ip tuntap add dev {{ interface }} mode tap
|
||||
when: "type == 'tap' and state == 'present'
|
||||
and interface not in current_interfaces"
|
||||
|
||||
- name: Delete tap interface {{ interface }}
|
||||
shell: ip tuntap del dev {{ interface }} mode tap
|
||||
when: "type == 'tap' and state == 'absent' and
|
||||
interface in current_interfaces"
|
||||
@@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include: get-current_interfaces.yml
|
||||
- debug:
|
||||
msg: "current_interfaces: {{ current_interfaces }}"
|
||||
Reference in New Issue
Block a user