1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
---
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2017 Ericsson AB and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
- name: ensure glean rules are removed
file:
path: "/etc/udev/rules.d/99-glean.rules"
state: absent
- name: Determine required packages
set_fact:
network_packages:
- bridge-utils
- "{{ (ansible_pkg_mgr in ['zypper', 'apt']) | ternary('iproute2', 'iproute') }}"
- "{{ (ansible_pkg_mgr == 'apt') | ternary('vlan', 'bridge-utils') }}"
- iptables
- name: Ensure networking packages are present
package:
name: "{{ network_packages }}"
state: present
- name: Ensure local facts directory exists
file:
path: "/etc/ansible/facts.d"
state: directory
# NOTE(hwoarang) We have to check all levels of the local fact before we add it
# otherwise Ansible will fail.
- name: Record initial active interface
ini_file:
create: yes
section: network
state: present
option: xci_interface
value: "{{ ansible_default_ipv4.interface }}"
path: "/etc/ansible/facts.d/xci.fact"
when: ansible_local is not defined
or (ansible_local is defined and ansible_local.xci is not defined)
or (ansible_local is defined and ansible_local.xci is defined and ansible_local.xci.network is not defined)
or (ansible_local is defined and ansible_local.xci is defined and ansible_local.xci.network is defined and ansible_local.xci.network.xci_interface is not defined)
notify:
- Reload facts
- name: Run handlers
meta: flush_handlers
- block:
- name: configure modules
lineinfile:
dest: /etc/modules
state: present
create: yes
line: "8021q"
- name: add modules
modprobe:
name: 8021q
state: present
- name: ensure interfaces.d folder is empty
file:
state: "{{ item }}"
path: "/etc/network/interfaces.d"
with_items:
- absent
- directory
- name: ensure interfaces file is updated
template:
src: "{{ ansible_os_family | lower }}/{{ ansible_hostname }}.interface.j2"
dest: "/etc/network/interfaces"
- name: restart network service
shell: "/sbin/ifconfig {{ ansible_local.xci.network.xci_interface }} 0 && /sbin/ifdown -a && /sbin/ifup -a"
async: 15
poll: 0
when: ansible_os_family | lower == "debian"
- block:
- name: Configure networking on SUSE
template:
src: "{{ ansible_os_family | lower }}/suse.interface.j2"
dest: "/etc/sysconfig/network/ifcfg-{{ item.name }}"
with_items:
- { name: "{{ ansible_local.xci.network.xci_interface }}" }
- { name: "{{ ansible_local.xci.network.xci_interface }}.10", vlan_id: 10 }
- { name: "{{ ansible_local.xci.network.xci_interface }}.30", vlan_id: 30 }
- { name: "{{ ansible_local.xci.network.xci_interface }}.20", vlan_id: 20 }
- { name: "br-mgmt", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.10", ip: "{{ host_info[inventory_hostname].MGMT_IP }}/22" }
- { name: "br-vxlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.30", ip: "{{ host_info[inventory_hostname].VXLAN_IP }}/22" }
- { name: "br-vlan", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}", ip: "{{ host_info[inventory_hostname].VLAN_IP }}/24" }
- { name: "br-storage", bridge_ports: "{{ ansible_local.xci.network.xci_interface }}.20", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}/22" }
- name: Add postup/postdown scripts on SUSE
copy:
src: "network-config-suse"
dest: "/etc/sysconfig/network/scripts/network-config-suse"
mode: 0755
- name: Configure routes on SUSE
template:
src: "{{ ansible_os_family | lower }}/suse.routes.j2"
dest: "/etc/sysconfig/network/ifroute-{{ item.name }}"
with_items:
- { name: "br-vlan", gateway: "192.168.122.1", route: "default" }
- name: restart network service
service:
name: network
state: restarted
async: 15
poll: 0
when: ansible_os_family | lower == "suse"
- block:
- name: Configure networking on CentOS for interfaces
template:
src: "{{ ansible_os_family | lower }}/interface.ifcfg.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}"
with_items:
- { name: "{{ ansible_local.xci.network.xci_interface }}" , bridge: "br-vlan" }
- { name: "{{ ansible_local.xci.network.xci_interface }}.10", bridge: "br-mgmt" , vlan_id: 10 }
- { name: "{{ ansible_local.xci.network.xci_interface }}.20", bridge: "br-storage", vlan_id: 20 }
- { name: "{{ ansible_local.xci.network.xci_interface }}.30", bridge: "br-vxlan" , vlan_id: 30 }
- name: Configure networking on CentOS for bridges
template:
src: "{{ ansible_os_family | lower }}/bridge.ifcfg.j2"
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name }}"
with_items:
- { name: "br-vlan" , ip: "{{ host_info[inventory_hostname].VLAN_IP }}", prefix: 24 }
- { name: "br-mgmt" , ip: "{{ host_info[inventory_hostname].MGMT_IP }}", prefix: 22 }
- { name: "br-storage", ip: "{{ host_info[inventory_hostname].STORAGE_IP }}", prefix: 22 }
- { name: "br-vxlan" , ip: "{{ host_info[inventory_hostname].VXLAN_IP }}", prefix: 22 }
- name: Add default route through br-vlan
lineinfile:
path: "/etc/sysconfig/network-scripts/ifcfg-br-vlan"
line: "GATEWAY=192.168.122.1"
- name: restart network service
service:
name: network
state: restarted
async: 15
poll: 0
when: ansible_os_family | lower == "redhat"
- name: Wait for host to come back to life
local_action:
module: wait_for
host: "{{ ansible_host }}"
delay: 15
state: started
port: 22
connect_timeout: 10
timeout: 180
|