|
6 | 6 | # role to use a script for network reconfiguration. |
7 | 7 | # Tested on Debian Jessie / Ubuntu 14.04 LTS and with Ethernet, Bonding Interfaces |
8 | 8 |
|
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 |
68 | 14 |
|
69 | 15 | # Execute configuration change |
70 | 16 | - name: Execute Network Restart |
71 | | - shell: bash {{ mktemp_script.stdout }} | true |
| 17 | + shell: bash /etc/network/restart.sh | true |
72 | 18 |
|
73 | 19 | # Cleanup |
74 | 20 | - name: Cleanup Network Restart script |
75 | | - file: path={{ mktemp_script.stdout }} state=absent |
| 21 | + file: path=/etc/network/restart.sh state=absent |
0 commit comments