Add veth-pair role
This role configures a veth pair between an OVS bridge and another device.
This commit is contained in:
parent
9cbf9a55a6
commit
4c79cfa10b
26
ansible/roles/veth-pair/README.md
Normal file
26
ansible/roles/veth-pair/README.md
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Veth Pair
|
||||||
|
=========
|
||||||
|
|
||||||
|
This role creates a veth pair. It will plug one end into the specified OVS
|
||||||
|
bridge and, optionally, can plug the other end into a source Linux bridge.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
The host should have the `ip` and `ovs-vsctl` commands accessible. If
|
||||||
|
`veth_pair_plug_into_source` is enabled, the command `brctl` must also be
|
||||||
|
accessible.
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
- `veth_pair_ovs_link_name`: The name to give the veth link that plugs into the
|
||||||
|
OVS bridge.
|
||||||
|
- `veth_pair_ovs_bridge`: The name of the OVS bridge to plug into.
|
||||||
|
- `veth_pair_source_link_name`: The name to give the veth link that plugs into
|
||||||
|
the source device.
|
||||||
|
- `veth_pair_source_bridge`: The name of the source Linux bridge to plug into. Must be
|
||||||
|
specified if and only if `plug_into_source` is enabled.
|
||||||
|
- `plug_into_source`: Whether or not to plug the source end of the veth pair
|
||||||
|
into a Linux bridge. If enabled, `source_bridge`, `source_bridge` must also
|
||||||
|
be specified. Default is `false`.
|
3
ansible/roles/veth-pair/defaults/main.yml
Normal file
3
ansible/roles/veth-pair/defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
# Whether or not to plug the source end of the veth pair into a Linux bridge.
|
||||||
|
veth_pair_plug_into_source: false
|
29
ansible/roles/veth-pair/tasks/main.yml
Normal file
29
ansible/roles/veth-pair/tasks/main.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
- name: Create veth pair
|
||||||
|
command: >
|
||||||
|
ip link add dev {{ veth_pair_ovs_link_name }}
|
||||||
|
type veth
|
||||||
|
peer name {{ veth_pair_source_link_name }}
|
||||||
|
register: res
|
||||||
|
changed_when: res.rc == 0
|
||||||
|
# Return code 2 means the veth pair already exists
|
||||||
|
failed_when: res.rc not in [0, 2]
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Plug veth into OVS bridge
|
||||||
|
openvswitch_port:
|
||||||
|
bridge: "{{ veth_pair_ovs_bridge }}"
|
||||||
|
port: "{{ veth_pair_ovs_link_name }}"
|
||||||
|
become: true
|
||||||
|
|
||||||
|
- name: Plug veth into source bridge
|
||||||
|
command: >
|
||||||
|
brctl addif {{ veth_pair_source_bridge }}
|
||||||
|
{{ veth_pair_source_link_name }}
|
||||||
|
register: res
|
||||||
|
failed_when:
|
||||||
|
- res.rc != 0
|
||||||
|
- "'already a member of a bridge' not in res.stderr"
|
||||||
|
changed_when: "'already a member of a bridge' not in res.stderr"
|
||||||
|
when: veth_pair_plug_into_source | bool
|
||||||
|
become: true
|
Loading…
x
Reference in New Issue
Block a user