2 # Copyright 2015, Rackspace US, Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 - name: Ensure that /etc/network/interfaces.d/ exists (Debian)
18 path: /etc/network/interfaces.d/
21 - networking-dir-create
23 - ansible_pkg_mgr == 'apt'
25 - name: Copy AIO network configuration (Debian)
27 src: osa_interfaces.cfg.j2
28 dest: /etc/network/interfaces.d/osa_interfaces.cfg
29 register: osa_interfaces
31 - bootstrap_host_aio_config | bool
32 - ansible_pkg_mgr == 'apt'
34 - networking-interfaces-file
36 - name: Copy network configuration (RedHat)
38 src: "redhat_interface_{{ item.type | default('default') }}.cfg.j2"
39 dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt') }}"
40 with_items: "{{ bridges }}"
41 register: network_interfaces_rhel
43 - ansible_pkg_mgr == 'yum'
45 - name: Create alias file when required (RedHat)
47 src: "redhat_interface_alias.cfg.j2"
48 dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt')}}:0"
49 with_items: "{{ bridges }}"
51 - ansible_pkg_mgr == 'yum'
52 - item.alias is defined
54 - name: Put down post-up script for veth-peer interfaces (RedHat)
56 src: "redhat_interface_{{ item[0] | default('default') }}.cfg.j2"
57 dest: "/etc/sysconfig/network-scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
60 - [ "ifup-post", "ifdown-post" ]
63 - item[1].veth_peer is defined
64 - ansible_pkg_mgr == 'yum'
66 - name: Ensure the postup/postdown scripts are loaded (RedHat)
68 dest: "/etc/sysconfig/network-scripts/{{ item[0] }}"
69 line: ". /etc/sysconfig/network-scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
70 insertbefore: "^exit 0"
72 - [ "ifup-post", "ifdown-post" ]
75 - item[1].veth_peer is defined
76 - ansible_pkg_mgr == 'yum'
78 - name: Copy multinode network configuration (Debian)
80 src: osa_interfaces_multinode.cfg.j2
81 dest: /etc/network/interfaces.d/osa_interfaces.cfg
82 register: osa_multinode_interfaces
84 - not bootstrap_host_aio_config | bool
85 - ansible_pkg_mgr == 'apt'
87 - networking-interfaces-file
89 - name: Ensure our interfaces.d configuration files are loaded automatically (Debian)
91 dest: /etc/network/interfaces
92 line: "source /etc/network/interfaces.d/*.cfg"
94 - ansible_pkg_mgr == 'apt'
96 - networking-interfaces-load
98 - name: Shut down the network interfaces
99 command: "ifdown {{ item.name }}"
100 when: osa_interfaces | changed or osa_multinode_interfaces | changed or network_interfaces_rhel | changed
101 with_items: "{{ bridges }}"
103 - networking-interfaces-stop
105 - name: Shut down the encapsulation network interfaces
106 command: "ifdown {{ item.key }}"
108 - osa_multinode_interfaces | changed
109 - bootstrap_host_encapsulation_enabled | bool
110 with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
112 - networking-interfaces-stop
114 - name: Start the encapsulation network interfaces
115 command: "ifup {{ item.key }}"
117 - osa_multinode_interfaces | changed
118 - bootstrap_host_encapsulation_enabled | bool
119 with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
121 - networking-interfaces-start
123 - name: Start the network interfaces
124 command: "ifup {{ item.name }}"
125 when: osa_interfaces | changed or network_interfaces_rhel | changed
126 with_items: "{{ bridges }}"
128 - networking-interfaces-start
130 - name: Updating the facts due to net changes
132 filter: "ansible_br*"