forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_network.yaml
153 lines (128 loc) · 5.23 KB
/
02_network.yaml
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
# Required Python packages:
#
# ansible
# openstackclient
# openstacksdk
# netaddr
- import_playbook: common.yaml
- hosts: all
gather_facts: no
tasks:
- name: 'Create the cluster network'
os_network:
name: "{{ os_network }}"
- name: 'Set the cluster network tag'
command:
cmd: "openstack network set --tag {{ cluster_id_tag }} {{ os_network }}"
- name: 'Create a subnet'
os_subnet:
name: "{{ os_subnet }}"
network_name: "{{ os_network }}"
cidr: "{{ os_subnet_range }}"
allocation_pool_start: "{{ os_subnet_range | next_nth_usable(10) }}"
allocation_pool_end: "{{ os_subnet_range | ipaddr('last_usable') }}"
- name: 'Set the cluster subnet tag'
command:
cmd: "openstack subnet set --tag {{ cluster_id_tag }} {{ os_subnet }}"
- name: 'Create the service network'
os_network:
name: "{{ os_svc_network }}"
when: os_networking_type == "Kuryr"
- name: 'Set the service network tag'
command:
cmd: "openstack network set --tag {{ cluster_id_tag }} {{ os_svc_network }}"
when: os_networking_type == "Kuryr"
- name: 'Computing facts for service subnet'
set_fact:
first_ip_svc_subnet_range: "{{ svc_subnet_range | ipv4('network') }}"
last_ip_svc_subnet_range: "{{ svc_subnet_range | ipaddr('last_usable') |ipmath(1) }}"
first_ip_os_svc_network_range: "{{ os_svc_network_range | ipv4('network') }}"
last_ip_os_svc_network_range: "{{ os_svc_network_range | ipaddr('last_usable') |ipmath(1) }}"
allocation_pool: ""
when: os_networking_type == "Kuryr"
- name: 'Get first part of OpenStack network'
set_fact:
allocation_pool: "{{ allocation_pool + '--allocation-pool start={{ first_ip_os_svc_network_range | ipmath(1) }},end={{ first_ip_svc_subnet_range |ipmath(-1) }}' }}"
when:
- os_networking_type == "Kuryr"
- first_ip_svc_subnet_range != first_ip_os_svc_network_range
- name: 'Get last part of OpenStack network'
set_fact:
allocation_pool: "{{ allocation_pool + ' --allocation-pool start={{ last_ip_svc_subnet_range | ipmath(1) }},end={{ last_ip_os_svc_network_range |ipmath(-1) }}' }}"
when:
- os_networking_type == "Kuryr"
- last_ip_svc_subnet_range != last_ip_os_svc_network_range
- name: 'Get end of allocation'
set_fact:
gateway_ip: "{{ allocation_pool.split('=')[-1] }}"
when: os_networking_type == "Kuryr"
- name: 'replace last IP'
set_fact:
allocation_pool: "{{ allocation_pool | replace(gateway_ip, gateway_ip | ipmath(-1))}}"
when: os_networking_type == "Kuryr"
- name: 'list service subnet'
command:
cmd: "openstack subnet list --name {{ os_svc_subnet }} --tag {{ cluster_id_tag }}"
when: os_networking_type == "Kuryr"
register: svc_subnet
- name: 'Create the service subnet'
command:
cmd: "openstack subnet create --ip-version 4 --gateway {{ gateway_ip }} --subnet-range {{ os_svc_network_range }} {{ allocation_pool }} --no-dhcp --network {{ os_svc_network }} --tag {{ cluster_id_tag }} {{ os_svc_subnet }}"
when:
- os_networking_type == "Kuryr"
- svc_subnet.stdout == ""
- name: 'list subnet pool'
command:
cmd: "openstack subnet pool list --name {{ subnet_pool }} --tags {{ cluster_id_tag }}"
when: os_networking_type == "Kuryr"
register: pods_subnet_pool
- name: 'Create pods subnet pool'
command:
cmd: "openstack subnet pool create --default-prefix-length {{ host_prefix }} --pool-prefix {{ cluster_network_cidrs }} --tag {{ cluster_id_tag }} {{ subnet_pool }}"
when:
- os_networking_type == "Kuryr"
- pods_subnet_pool.stdout == ""
- name: 'Create external router'
os_router:
name: "{{ os_router }}"
network: "{{ os_external_network }}"
interfaces:
- "{{ os_subnet }}"
- name: 'Set external router tag'
command:
cmd: "openstack router set --tag {{ cluster_id_tag }} {{ os_router }}"
when: os_networking_type == "Kuryr"
- name: 'Create the API port'
os_port:
name: "{{ os_port_api }}"
network: "{{ os_network }}"
security_groups:
- "{{ os_sg_master }}"
fixed_ips:
- subnet: "{{ os_subnet }}"
ip_address: "{{ os_subnet_range | next_nth_usable(5) }}"
- name: 'Set API port tag'
command:
cmd: "openstack port set --tag {{ cluster_id_tag }} {{ os_port_api }}"
- name: 'Create the Ingress port'
os_port:
name: "{{ os_port_ingress }}"
network: "{{ os_network }}"
security_groups:
- "{{ os_sg_worker }}"
fixed_ips:
- subnet: "{{ os_subnet }}"
ip_address: "{{ os_subnet_range | next_nth_usable(7) }}"
- name: 'Set the Ingress port tag'
command:
cmd: "openstack port set --tag {{ cluster_id_tag }} {{ os_port_ingress }}"
# NOTE: openstack ansible module doesn't allow attaching Floating IPs to
# ports, let's use the CLI instead
- name: 'Attach the API floating IP to API port'
command:
cmd: "openstack floating ip set --port {{ os_port_api }} {{ os_api_fip }}"
# NOTE: openstack ansible module doesn't allow attaching Floating IPs to
# ports, let's use the CLI instead
- name: 'Attach the Ingress floating IP to Ingress port'
command:
cmd: "openstack floating ip set --port {{ os_port_ingress }} {{ os_ingress_fip }}"