diff --git a/ansible/roles/veth/tasks/Debian.yml b/ansible/roles/veth/tasks/Debian.yml new file mode 100644 index 000000000..bfd2b6ff0 --- /dev/null +++ b/ansible/roles/veth/tasks/Debian.yml @@ -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 diff --git a/ansible/roles/veth/tasks/RedHat.yml b/ansible/roles/veth/tasks/RedHat.yml new file mode 100644 index 000000000..e8a5972ec --- /dev/null +++ b/ansible/roles/veth/tasks/RedHat.yml @@ -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 diff --git a/ansible/roles/veth/tasks/main.yml b/ansible/roles/veth/tasks/main.yml index e8a5972ec..2c28f1229 100644 --- a/ansible/roles/veth/tasks/main.yml +++ b/ansible/roles/veth/tasks/main.yml @@ -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"