Remove dependency on bridge-utils
bridge-utils is considered legacy and many distributions do not ship it as default. Change-Id: Id2f9d779d12a5135d7d7e7a4783c6f3a0c8647ca Story: 2004302 Task: 27861
This commit is contained in:
parent
583d3232ae
commit
602fdfa26b
@ -15,9 +15,7 @@ This role manages a veth pair. Actions:
|
|||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
The host should have the `ip` and `ovs-vsctl` commands accessible. If
|
The host should have the `ip` and `ovs-vsctl` commands accessible.
|
||||||
`veth_pair_plug_into_source` is enabled, the command `brctl` must also be
|
|
||||||
accessible.
|
|
||||||
|
|
||||||
Role Variables
|
Role Variables
|
||||||
--------------
|
--------------
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
---
|
---
|
||||||
- name: Unplug veth from source bridge
|
- block:
|
||||||
command: >-
|
- include_tasks: is-attached.yml
|
||||||
brctl delif {{ veth_pair_source_bridge }}
|
vars:
|
||||||
{{ veth_pair_source_link_name }}
|
bridge: "{{ veth_pair_source_bridge }}"
|
||||||
register: res
|
interface: "{{ veth_pair_source_link_name }}"
|
||||||
failed_when:
|
|
||||||
- res.rc != 0
|
- name: Unplug veth from source bridge
|
||||||
# Case where veth is already unplugged.
|
command: >-
|
||||||
- not (res.rc == 1 and 'does not exist' in res.stderr)
|
ip link set {{ veth_pair_source_link_name }} nomaster
|
||||||
changed_when: res.rc == 0
|
when:
|
||||||
|
- veth_pair_is_attached
|
||||||
|
become: true
|
||||||
when: veth_pair_plug_into_source | bool
|
when: veth_pair_plug_into_source | bool
|
||||||
become: true
|
|
||||||
|
|
||||||
- name: Delete veth pair
|
- name: Delete veth pair
|
||||||
command: >-
|
command: >-
|
||||||
|
22
ansible/roles/veth-pair/tasks/is-attached.yml
Normal file
22
ansible/roles/veth-pair/tasks/is-attached.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
# This will determine if interface is attached to bridge and set a fact called
|
||||||
|
# veth_pair_is_attached containing the result
|
||||||
|
|
||||||
|
- name: Set a default value for veth_pair_is_attached
|
||||||
|
set_fact:
|
||||||
|
veth_pair_is_attached: false
|
||||||
|
|
||||||
|
- name: Speculatively check {{ interface }}'s master
|
||||||
|
command: >-
|
||||||
|
realpath /sys/class/net/{{ interface }}/master
|
||||||
|
register: master_result
|
||||||
|
failed_when: false
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Determine if {{ interface }} is attached to {{ bridge }}
|
||||||
|
vars:
|
||||||
|
master: "{{ master_result.stdout | basename }}"
|
||||||
|
set_fact:
|
||||||
|
veth_pair_is_attached: "{{ master == bridge }}"
|
||||||
|
when: master_result.rc == 0
|
@ -23,14 +23,17 @@
|
|||||||
port: "{{ veth_pair_ovs_link_name }}"
|
port: "{{ veth_pair_ovs_link_name }}"
|
||||||
become: true
|
become: true
|
||||||
|
|
||||||
- name: Plug veth into source bridge
|
- block:
|
||||||
command: >-
|
- include_tasks: is-attached.yml
|
||||||
brctl addif {{ veth_pair_source_bridge }}
|
vars:
|
||||||
{{ veth_pair_source_link_name }}
|
bridge: "{{ veth_pair_source_bridge }}"
|
||||||
register: res
|
interface: "{{ veth_pair_source_link_name }}"
|
||||||
failed_when:
|
|
||||||
- res.rc != 0
|
- name: Plug veth into source bridge
|
||||||
- "'already a member of a bridge' not in res.stderr"
|
command: >-
|
||||||
changed_when: "'already a member of a bridge' not in res.stderr"
|
ip link set {{ veth_pair_source_link_name }} master
|
||||||
|
{{ veth_pair_source_bridge }}
|
||||||
|
when:
|
||||||
|
- not veth_pair_is_attached
|
||||||
|
become: true
|
||||||
when: veth_pair_plug_into_source | bool
|
when: veth_pair_plug_into_source | bool
|
||||||
become: true
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user