Initial commit
[ta/infra-ansible.git] / roles / bootstrap-host / tasks / prepare_networking.yml
1 ---
2 # Copyright 2015, Rackspace US, Inc.
3 #
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
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 - name: Ensure that /etc/network/interfaces.d/ exists (Debian)
17   file:
18     path: /etc/network/interfaces.d/
19     state: directory
20   tags:
21     - networking-dir-create
22   when:
23     - ansible_pkg_mgr == 'apt'
24
25 - name: Copy AIO network configuration (Debian)
26   template:
27     src: osa_interfaces.cfg.j2
28     dest: /etc/network/interfaces.d/osa_interfaces.cfg
29   register: osa_interfaces
30   when:
31     - bootstrap_host_aio_config | bool
32     - ansible_pkg_mgr == 'apt'
33   tags:
34     - networking-interfaces-file
35
36 - name: Copy network configuration (RedHat)
37   template:
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
42   when:
43     - ansible_pkg_mgr == 'yum'
44
45 - name: Create alias file when required (RedHat)
46   template:
47     src: "redhat_interface_alias.cfg.j2"
48     dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt')}}:0"
49   with_items: "{{ bridges }}"
50   when:
51     - ansible_pkg_mgr == 'yum'
52     - item.alias is defined
53
54 - name: Put down post-up script for veth-peer interfaces (RedHat)
55   template:
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') }}"
58     mode: "0755"
59   with_nested:
60     - [ "ifup-post", "ifdown-post" ]
61     - "{{ bridges }}"
62   when:
63     - item[1].veth_peer is defined
64     - ansible_pkg_mgr == 'yum'
65
66 - name: Ensure the postup/postdown scripts are loaded (RedHat)
67   lineinfile:
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"
71   with_nested:
72     - [ "ifup-post", "ifdown-post" ]
73     - "{{ bridges }}"
74   when:
75     - item[1].veth_peer is defined
76     - ansible_pkg_mgr == 'yum'
77
78 - name: Copy multinode network configuration (Debian)
79   template:
80     src: osa_interfaces_multinode.cfg.j2
81     dest: /etc/network/interfaces.d/osa_interfaces.cfg
82   register: osa_multinode_interfaces
83   when:
84     - not bootstrap_host_aio_config | bool
85     - ansible_pkg_mgr == 'apt'
86   tags:
87     - networking-interfaces-file
88
89 - name: Ensure our interfaces.d configuration files are loaded automatically (Debian)
90   lineinfile:
91     dest: /etc/network/interfaces
92     line: "source /etc/network/interfaces.d/*.cfg"
93   when:
94     - ansible_pkg_mgr == 'apt'
95   tags:
96     - networking-interfaces-load
97
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 }}"
102   tags:
103     - networking-interfaces-stop
104
105 - name: Shut down the encapsulation network interfaces
106   command: "ifdown {{ item.key }}"
107   when:
108    - osa_multinode_interfaces | changed
109    - bootstrap_host_encapsulation_enabled | bool
110   with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
111   tags:
112     - networking-interfaces-stop
113
114 - name: Start the encapsulation network interfaces
115   command: "ifup {{ item.key }}"
116   when:
117     - osa_multinode_interfaces | changed
118     - bootstrap_host_encapsulation_enabled | bool
119   with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
120   tags:
121     - networking-interfaces-start
122
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 }}"
127   tags:
128     - networking-interfaces-start
129
130 - name: Updating the facts due to net changes
131   setup:
132     filter: "ansible_br*"
133   tags:
134     - networking