Skip to content

Commit 0cf8f22

Browse files
committed
removed old vlan package (iproute2 is better), new network restart script, fixed some issues with missing gateway or bridge_port configurations
1 parent abbcad4 commit 0cf8f22

10 files changed

+77
-88
lines changed

tasks/main.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,9 @@
4747
register: bridge_result
4848

4949
- name: Create the network configuration file for port on the bridge devices
50-
template: src=bridge_port_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item.1 }}
51-
with_subelements:
52-
- "{{ network_bridge_interfaces }}"
53-
- bridge_ports
50+
template: src=bridge_port_{{ ansible_os_family }}.j2 dest={{ net_path }}/ifcfg-{{ item }}
51+
with_items:
52+
- "{{ network_bridge_interfaces | selectattr('bridge_ports', 'defined') | list }}"
5453
when: network_bridge_interfaces is defined
5554
register: bridge_port_result
5655

tasks/restartscript.yml

+7-61
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,16 @@
66
# role to use a script for network reconfiguration.
77
# Tested on Debian Jessie / Ubuntu 14.04 LTS and with Ethernet, Bonding Interfaces
88

9-
- name: Create temporary interface script for seamless network reload
10-
shell: mktemp
11-
register: mktemp_script
12-
13-
- lineinfile: line="{{ item }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF
14-
with_items:
15-
- "ifdown "
16-
- "sleep 1"
17-
- "ifup "
18-
19-
# Shutdown current network configuration
20-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifdown .*)'
21-
with_items: "{{ ether_result.results }}"
22-
when: ether_result is defined and 'results' in ether_result and item.changed
23-
24-
- lineinfile: line="\1 {{ item.item.1 }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifdown .*)'
25-
with_items: "{{ bond_port_result.results }}"
26-
when: bond_port_result is defined and 'results' in bond_port_result and item.changed
27-
28-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifdown .*)'
29-
with_items: "{{ bond_result.results }}"
30-
when: bond_result is defined and 'results' in bond_result and item.changed
31-
32-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifdown .*)'
33-
with_items: "{{ vlan_result.results }}"
34-
when: vlan_result is defined and item.changed
35-
36-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifdown .*)'
37-
with_items: "{{ bridge_result.results }}"
38-
when: bridge_result is defined and 'results' in bridge_result and item.changed
39-
40-
- lineinfile: line="\1 {{ item.item.1 }};" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifdown .*)'
41-
with_items: "{{ bridge_port_result.results }}"
42-
when: bridge_port_result is defined and 'results' in bridge_port_result and item.changed
43-
44-
# Start new network configuration
45-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifup .*)'
46-
with_items: "{{ ether_result.results }}"
47-
when: ether_result is defined and 'results' in ether_result and item.changed
48-
49-
- lineinfile: line="\1 {{ item.item.1 }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifup .*)'
50-
with_items: "{{ bond_port_result.results }}"
51-
when: bond_port_result is defined and 'results' in bond_port_result and item.changed
52-
53-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifup .*)'
54-
with_items: "{{ bond_result.results }}"
55-
when: bond_result is defined and 'results' in bond_result and item.changed
56-
57-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifup .*)'
58-
with_items: "{{ vlan_result.results }}"
59-
when: vlan_result is defined and item.changed
60-
61-
- lineinfile: line="\1 {{ item.item.device }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifup .*)'
62-
with_items: "{{ bridge_result.results }}"
63-
when: bridge_result is defined and 'results' in bridge_result and item.changed
64-
65-
- lineinfile: line="\1 {{ item.item.1 }}" dest={{ mktemp_script.stdout }} state=present insertafter=EOF backrefs=True regexp='(ifup .*)'
66-
with_items: "{{ bridge_port_result.results }}"
67-
when: bridge_port_result is defined and 'results' in bridge_port_result and item.changed
9+
- name: Create a restart script
10+
template:
11+
src: restartscript.j2
12+
dest: /etc/network/restart.sh
13+
mode: 0755
6814

6915
# Execute configuration change
7016
- name: Execute Network Restart
71-
shell: bash {{ mktemp_script.stdout }} | true
17+
shell: bash /etc/network/restart.sh | true
7218

7319
# Cleanup
7420
- name: Cleanup Network Restart script
75-
file: path={{ mktemp_script.stdout }} state=absent
21+
file: path=/etc/network/restart.sh state=absent

templates/Debian_ipv4_config.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{% endif %}
2020
{% if item.gateway is defined and item.gateway != 'auto' %}
2121
gateway {{ item.gateway }}
22-
{% elif item.cidr is defined and item.gateway == 'auto' %}
22+
{% elif item.cidr is defined and item.gateway is defined and item.gateway == 'auto' %}
2323
gateway {{ item.cidr | ipaddr('1') | ipaddr('address') }}
2424
{% endif %}
2525

templates/Debian_ipv6_config.j2

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if item.ipv6_address is defined %}
2+
address {{ item.ipv6_address | ipaddr('address') }}
3+
netmask {{ item.ipv6_address | ipaddr('prefix') }}
4+
{% if item.ipv6_gateway is defined and item.ipv6_gateway != 'auto' %}
5+
gateway {{ item.ipv6_gateway }}
6+
{% elif item.ipv6_gateway is defined and item.ipv6_gateway == 'auto' %}
7+
gateway {{ item.ipv6_address | ipaddr('1') | ipaddr('address') }}
8+
{% endif %}
9+
{% endif %}

templates/bond_Debian.j2

+1-7
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,7 @@ iface {{ item.device }} inet {% if item.bootproto is defined %}{{ item.bootproto
7474

7575
{% if item.ipv6_address is defined %}
7676
iface {{ item.device }} inet6 static
77-
address {{ item.ipv6_address | ipaddr('address') }}
78-
netmask {{ item.ipv6_address | ipaddr('prefix') }}
79-
{% if item.ipv6_gateway is defined %}
80-
gateway {{ item.ipv6_gateway }}
81-
{% else %}
82-
gateway {{ item.ipv6_address | ipaddr('1') | ipaddr('address') }}
83-
{% endif %}
77+
{% include 'Debian_ipv6_config.j2' %}
8478
{% if item.ipv6_options is defined %}
8579
{% for option in item.ipv6_options %}
8680
{{ option }}

templates/bridge_Debian.j2

+1-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ iface {{ item.device }} inet {% if item.bootproto is defined %}{{ item.bootproto
5454

5555
{% if item.ipv6_address is defined %}
5656
iface {{ item.device }} inet6 static
57-
address {{ item.ipv6_address | ipaddr('address') }}
58-
netmask {{ item.ipv6_address | ipaddr('prefix') }}
59-
{% if item.ipv6_gateway is defined %}
60-
gateway {{ item.ipv6_gateway }}
61-
{% else %}
62-
gateway {{ item.ipv6_address | ipaddr('1') | ipaddr('address') }}
63-
{% endif %}
57+
{% include 'Debian_ipv6_config.j2' %}
6458
{% if item.ipv6_options is defined %}
6559
{% for option in item.ipv6_options %}
6660
{{ option }}

templates/ethernet_Debian.j2

+1-7
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,7 @@ iface {{ item.device }} inet {% if item.bootproto is defined %}{{ item.bootproto
1616

1717
{% if item.ipv6_address is defined %}
1818
iface {{ item.device }} inet6 static
19-
address {{ item.ipv6_address | ipaddr('address') }}
20-
netmask {{ item.ipv6_address | ipaddr('prefix') }}
21-
{% if item.ipv6_gateway is defined %}
22-
gateway {{ item.ipv6_gateway }}
23-
{% else %}
24-
gateway {{ item.ipv6_address | ipaddr('1') | ipaddr('address') }}
25-
{% endif %}
19+
{% include 'Debian_ipv6_config.j2' %}
2620
{% if item.ipv6_options is defined %}
2721
{% for option in item.ipv6_options %}
2822
{{ option }}

templates/restartscript.j2

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Shutdown current network configuration
2+
# Ethernet
3+
{% if ether_result is defined and 'results' in ether_result %}{% for item in ether_result.results %}
4+
ifdown {{ item.item.device }}
5+
{% endfor %}{% endif %}
6+
# Bonding
7+
{% if bond_port_result is defined and 'results' in bond_port_result %}{% for item in bond_port_result.results %}
8+
ifdown {{ item.item.1 }}
9+
{% endfor %}{% endif %}
10+
{% if bond_result is defined and 'results' in bond_result %}{% for item in bond_result.results %}
11+
ifdown {{ item.item.device }}
12+
{% endfor %}{% endif %}
13+
# Vlan
14+
{% if vlan_result is defined %}{% for item in vlan_result.results %}
15+
ifdown {{ item.item.device }}
16+
{% endfor %}{% endif %}
17+
# Bridge
18+
{% if bridge_port_result is defined and 'results' in bridge_port_result %}{% for item in bridge_port_result.results %}
19+
ifdown {{ item.item.1 }}
20+
{% endfor %}{% endif %}
21+
{% if bridge_result is defined and 'results' in bridge_result %}{% for item in bridge_result.results %}
22+
ifdown {{ item.item.device }}
23+
{% endfor %}{% endif %}
24+
25+
# Short delay to prevent issues
26+
sleep 1
27+
28+
# Start new network configuration
29+
# Ethernet
30+
{% if ether_result is defined and 'results' in ether_result %}{% for item in ether_result.results %}
31+
ifup {{ item.item.device }}
32+
{% endfor %}{% endif %}
33+
# Bonding
34+
{% if bond_port_result is defined and 'results' in bond_port_result %}{% for item in bond_port_result.results %}
35+
ifup {{ item.item.1 }}
36+
{% endfor %}{% endif %}
37+
{% if bond_result is defined and 'results' in bond_result %}{% for item in bond_result.results %}
38+
ifup {{ item.item.device }}
39+
{% endfor %}{% endif %}
40+
# Vlan
41+
{% if vlan_result is defined %}{% for item in vlan_result.results %}
42+
ifup {{ item.item.device }}
43+
{% endfor %}{% endif %}
44+
# Bridge
45+
{% if bridge_port_result is defined and 'results' in bridge_port_result %}{% for item in bridge_port_result.results %}
46+
ifup {{ item.item.1 }}
47+
{% endfor %}{% endif %}
48+
{% if bridge_result is defined and 'results' in bridge_result %}{% for item in bridge_result.results %}
49+
ifup {{ item.item.device }}
50+
{% endfor %}{% endif %}
51+
52+

templates/route_Debian.j2

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
{% if item.route is defined %}
12
{% for i in item.route %}
23
{% if i.cidr is defined %}
34
up ip route add {{ i.cidr }} via {{ i.gateway }} dev {{ item.device }}
45
{% else %}
56
up route add -net {{ i.network }} netmask {{ i.netmask }} gw {{ i.gateway }} {{ item.device }}
67
{% endif %}
78
{% endfor %}
9+
{% endif %}

vars/Debian.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ network_pkgs:
33
- python-selinux
44
- bridge-utils
55
- ifenslave
6-
- vlan
76
- iproute2
87

98
net_path: "/etc/network/interfaces.d"

0 commit comments

Comments
 (0)