Merge "Ubuntu: support non-persistent veth configuration"

This commit is contained in:
Zuul 2021-03-01 17:44:04 +00:00 committed by Gerrit Code Review
commit a9bf637cc5
3 changed files with 86 additions and 42 deletions

View File

@ -0,0 +1,42 @@
---
# FIXME: Not persistent!
- name: Ensure veth pair exists (Debian)
command:
cmd: "ip link add dev {{ item.device }} type veth peer name {{ item.peer_device }}"
creates: "/sys/class/net/{{ item.device }}"
become: true
with_items: "{{ veth_interfaces }}"
- name: Set veth MTU (Debian)
command: "ip link set {{ item.device }} mtu {{ item.mtu }}"
become: true
with_items: "{{ veth_interfaces }}"
when: item.mtu is defined and item.mtu
- name: Set veth peer MTU (Debian)
command: "ip link set {{ item.peer_device }} mtu {{ item.peer_mtu }}"
become: true
with_items: "{{ veth_interfaces }}"
when: item.peer_mtu is defined and item.peer_mtu
- name: Plug veth into bridge (Debian)
command: "ip link set {{ item.device }} master {{ item.bridge }}"
become: true
with_items: "{{ veth_interfaces }}"
when: item.bridge is defined
- name: Plug veth peer into bridge (Debian)
command: "ip link set {{ item.peer_device }} master {{ item.peer_bridge }}"
become: true
with_items: "{{ veth_interfaces }}"
when: item.peer_bridge is defined
- name: Ensure veth is up (Debian)
command: "ip link set {{ item.device }} up"
with_items: "{{ veth_interfaces }}"
become: true
- name: Ensure veth peer is up (Debian)
command: "ip link set {{ item.peer_device }} up"
with_items: "{{ veth_interfaces }}"
become: true

View File

@ -0,0 +1,43 @@
---
- name: Ensure veth sysconfig network control scripts exist
copy:
src: "{{ item }}"
dest: "{{ network_scripts_dir }}/{{ item }}"
owner: root
group: root
mode: 0755
with_items:
- "ifup-veth"
- "ifdown-veth"
become: True
register: ctl_result
- name: Ensure veth sysconfig network interface files exist
template:
src: ifcfg-veth.j2
dest: "{{ network_scripts_dir }}/ifcfg-{{ item.device }}"
owner: root
group: root
mode: 0644
with_items: "{{ veth_interfaces }}"
become: True
register: veth_result
- name: Ensure veth peer sysconfig network interface files exist
template:
src: ifcfg-peer.j2
dest: "{{ network_scripts_dir }}/ifcfg-{{ item.peer_device }}"
owner: root
group: root
mode: 0644
with_items: "{{ veth_interfaces }}"
become: True
register: peer_result
- name: Bounce veth interfaces
shell: ifdown {{ item[0].item.device }} ; ifup {{ item[0].item.device }}
with_together:
- "{{ veth_result.results }}"
- "{{ peer_result.results }}"
when: ctl_result is changed or item[0] is changed or item[1] is changed
become: True

View File

@ -1,43 +1,2 @@
---
- name: Ensure veth sysconfig network control scripts exist
copy:
src: "{{ item }}"
dest: "{{ network_scripts_dir }}/{{ item }}"
owner: root
group: root
mode: 0755
with_items:
- "ifup-veth"
- "ifdown-veth"
become: True
register: ctl_result
- name: Ensure veth sysconfig network interface files exist
template:
src: ifcfg-veth.j2
dest: "{{ network_scripts_dir }}/ifcfg-{{ item.device }}"
owner: root
group: root
mode: 0644
with_items: "{{ veth_interfaces }}"
become: True
register: veth_result
- name: Ensure veth peer sysconfig network interface files exist
template:
src: ifcfg-peer.j2
dest: "{{ network_scripts_dir }}/ifcfg-{{ item.peer_device }}"
owner: root
group: root
mode: 0644
with_items: "{{ veth_interfaces }}"
become: True
register: peer_result
- name: Bounce veth interfaces
shell: ifdown {{ item[0].item.device }} ; ifup {{ item[0].item.device }}
with_together:
- "{{ veth_result.results }}"
- "{{ peer_result.results }}"
when: ctl_result is changed or item[0] is changed or item[1] is changed
become: True
- include_tasks: "{{ ansible_os_family }}.yml"