-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision_networks.yml
99 lines (85 loc) · 3.47 KB
/
provision_networks.yml
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
---
- name: Create networks
hosts: hypervisor
gather_facts: yes
any_errors_fatal: true
tasks:
- name: Download custom network configuration
get_url:
url: "{{ provision.topology.net.url }}"
dest: "{{ playbook_dir }}/defaults/topology/networks/{{ provision.topology.network }}.yml"
force: yes
when: provision.topology.net is defined and provision.topology.net.url
- name: get networks dict
include_vars: "{{ provision.topology.network }}"
- name: merge overriden settings to the separate var
set_fact:
networks: "{{ networks|default({}) | combine(item.value, recursive=True) }}"
when: item.key == 'networks'
with_dict: "{{ override|default({}) }}"
- name: Get uniq id for current deployment
set_fact:
prefix: "{{ ansible_local.run.keys()[0] }}"
when: provision.prefix is defined
- name: set net prefix
set_fact:
net: "{{ ansible_local.run[prefix].net if prefix is defined else 0 }}"
- name: set data net prefix
set_fact:
data_net: "{{ ansible_local.run[prefix].data_net if prefix is defined else 24 }}"
- name: Update network dict with prefix
set_fact:
networks: "{{ networks|combine({item.key: {'name': prefix|default('') + (prefix is defined|ternary('-','')) + item.value.name}}, recursive=True) }}"
with_dict: "{{ networks }}"
- name: Check if interfaces have inet6 address family capabilities
shell: "ip addr show | grep inet6"
ignore_errors: True
register: ipv6_addr
- name: Check if IPv6 enabled on host
shell: "grep -q ^0$ /sys/module/ipv6/parameters/disable"
ignore_errors: True
register: ipv6_sys
- fail:
msg: "Network '{{ item.value.name }}' requires IPv6, but modules aren't loaded..."
when:
- item.value.ipv6 is defined
- (ipv6_addr.rc != 0 or ipv6_sys.rc != 0 )
with_dict: "{{ networks }}"
- name: enable router advertisements
sysctl:
name: "net.ipv6.conf.{{ ansible_default_ipv6['interface'] }}.accept_ra"
value: 2
sysctl_set: yes
state: present
reload: yes
when: "'interface' in ansible_default_ipv6"
- name: create bridged network
include_tasks: tasks/bridged_network.yml
vars:
nic_settings: "{{ item }}"
nic_data: "{{ (item.nic == '') | ternary(hostvars[inventory_hostname]['ansible_' + ansible_default_ipv4.interface],
hostvars[inventory_hostname]['ansible_' + item.nic]|default('')) }}"
with_items:
"{{ networks.values() | selectattr('forward', 'defined') | selectattr('forward', 'equalto', 'bridge') | list }}"
when: "networks is defined"
- name: check for existing networks
virt_net:
command: "list_nets"
register: network_list
- name: create the networks for the topology
virt_net:
command: "define"
name: "{{ item.value.name }}"
xml: "{{ lookup('template', 'templates/network.xml.j2') }}"
when: "item.value.name not in network_list.list_nets"
with_dict: "{{ networks }}"
- name: set autostart to the created networks
virt_net:
autostart: "{{ item.value.autostart | default('yes') }}"
name: "{{ item.value.name }}"
with_dict: "{{ networks }}"
- name: check if network is active
virt_net:
name: "{{ item.value.name }}"
state: active
with_dict: "{{ networks }}"