Skip to content

Commit a81f744

Browse files
gryfMaysaMacedo
authored andcommitted
OpenStack: Add dualstack related tasks for creating network resources.
Also introducing update-network-resources.yaml playbook for tagging user defined resources.
1 parent 2b07d2c commit a81f744

File tree

2 files changed

+161
-39
lines changed

2 files changed

+161
-39
lines changed

upi/openstack/network.yaml

Lines changed: 99 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@
55
# openstacksdk
66
# netaddr
77

8-
- ansible.builtin.import_playbook: common.yaml
9-
108
- hosts: all
119
gather_facts: no
1210

1311
tasks:
14-
- name: 'Create the primary cluster network'
12+
- name: 'Create the cluster network'
1513
openstack.cloud.network:
1614
name: "{{ os_network }}"
1715

18-
- name: 'Set tags on the primary cluster network'
19-
ansible.builtin.command:
20-
cmd: "openstack network set --tag {{ primary_cluster_network_tag }} --tag {{ cluster_id_tag }} {{ os_network }}"
21-
22-
- name: 'Create the primary cluster subnet'
16+
- name: 'Create the cluster IPv4 subnet'
2317
openstack.cloud.subnet:
2418
name: "{{ os_subnet }}"
2519
network_name: "{{ os_network }}"
@@ -28,9 +22,17 @@
2822
allocation_pool_end: "{{ os_subnet_range | ansible.utils.ipaddr('last_usable') }}"
2923
dns_nameservers: "{{ os_external_dns }}"
3024

31-
- name: 'Set tags on primary cluster subnet'
32-
ansible.builtin.command:
33-
cmd: "openstack subnet set --tag {{ cluster_id_tag }} {{ os_subnet }}"
25+
- name: 'Create the cluster IPv6 subnet'
26+
openstack.cloud.subnet:
27+
name: "{{ os_subnet6 }}"
28+
network_name: "{{ os_network }}"
29+
cidr: "{{ os_subnet6_range }}"
30+
ip_version: 6
31+
ipv6_address_mode: "{{ os_subnet6_address_mode }}"
32+
ipv6_ra_mode: "{{ os_subnet6_router_advertisements_mode }}"
33+
when:
34+
- os_subnet6_range is defined
35+
- os_subnet6_range|ansible.utils.ipv6
3436

3537
- name: 'Create external router'
3638
openstack.cloud.router:
@@ -40,49 +42,107 @@
4042
- "{{ os_subnet }}"
4143
when: os_external_network is defined and os_external_network|length>0
4244

43-
- name: 'Set external router tag'
44-
ansible.builtin.command:
45-
cmd: "openstack router set --tag {{ cluster_id_tag }} {{ os_router }}"
46-
when: os_external_network is defined and os_external_network|length>0
45+
- name: 'Add IPv6 subnet to the external router'
46+
openstack.cloud.router:
47+
name: "{{ os_router }}"
48+
interfaces:
49+
- "{{ os_subnet }}"
50+
- "{{ os_subnet6 }}"
51+
when:
52+
- os_subnet6_range is defined
53+
- os_subnet6_range|ansible.utils.ipv6
54+
- os_external_network is defined and os_external_network|length>0
4755

4856
- name: 'Create the API port'
4957
openstack.cloud.port:
5058
name: "{{ os_port_api }}"
5159
network: "{{ os_network }}"
52-
security_groups:
53-
- "{{ os_sg_master }}"
5460
fixed_ips:
5561
- subnet: "{{ os_subnet }}"
5662
ip_address: "{{ os_apiVIP }}"
63+
register: _api_ports
64+
when:
65+
- os_subnet6_range is not defined
5766

58-
- name: 'Set API port tag'
59-
ansible.builtin.command:
60-
cmd: "openstack port set --tag {{ cluster_id_tag }} {{ os_port_api }}"
67+
- set_fact:
68+
api_ports: "{{ _api_ports }}"
69+
when: _api_ports.changed
70+
71+
- name: 'Create the dualstack API port'
72+
openstack.cloud.port:
73+
name: "{{ os_port_api }}"
74+
network: "{{ os_network }}"
75+
register: _api_ports
76+
when:
77+
- os_subnet6_range is defined
78+
- os_subnet6_range|ansible.utils.ipv6
79+
80+
- set_fact:
81+
api_ports: "{{ _api_ports }}"
82+
when: _api_ports.changed
6183

6284
- name: 'Create the Ingress port'
6385
openstack.cloud.port:
6486
name: "{{ os_port_ingress }}"
6587
network: "{{ os_network }}"
66-
security_groups:
67-
- "{{ os_sg_worker }}"
6888
fixed_ips:
6989
- subnet: "{{ os_subnet }}"
7090
ip_address: "{{ os_ingressVIP }}"
91+
register: _ingress_ports
92+
when:
93+
- os_subnet6_range is not defined
94+
95+
- set_fact:
96+
ingress_ports: "{{ _ingress_ports }}"
97+
when: _ingress_ports.changed
98+
99+
- name: 'Create the dualstack Ingress port'
100+
openstack.cloud.port:
101+
name: "{{ os_port_ingress }}"
102+
network: "{{ os_network }}"
103+
register: _ingress_ports
104+
when:
105+
- os_subnet6_range is defined
106+
- os_subnet6_range|ansible.utils.ipv6
107+
108+
- set_fact:
109+
ingress_ports: "{{ _ingress_ports }}"
110+
when: _ingress_ports.changed
111+
112+
- name: 'Populate inventory with API addresses'
113+
shell: |
114+
python -c 'import yaml
115+
path = "inventory.yaml"
116+
ipv4 = "{{ item.ip_address|ansible.utils.ipv4 }}"
117+
ipv6 = "{{ item.ip_address|ansible.utils.ipv6 }}"
118+
if ipv4 != "False":
119+
key = "os_apiVIP"
120+
ip = ipv4
121+
else:
122+
key = "os_apiVIP6"
123+
ip = ipv6
124+
data = yaml.safe_load(open(path))
125+
data["all"]["hosts"]["localhost"][key] = ip
126+
open(path, "w").write(yaml.dump(data, default_flow_style=False))'
127+
when:
128+
- api_ports.port is defined
129+
loop: "{{ api_ports.port.fixed_ips }}"
71130

72-
- name: 'Set the Ingress port tag'
73-
ansible.builtin.command:
74-
cmd: "openstack port set --tag {{ cluster_id_tag }} {{ os_port_ingress }}"
75-
76-
# NOTE: openstack ansible module doesn't allow attaching Floating IPs to
77-
# ports, let's use the CLI instead
78-
- name: 'Attach the API floating IP to API port'
79-
ansible.builtin.command:
80-
cmd: "openstack floating ip set --port {{ os_port_api }} {{ os_api_fip }}"
81-
when: os_api_fip is defined and os_api_fip|length>0
82-
83-
# NOTE: openstack ansible module doesn't allow attaching Floating IPs to
84-
# ports, let's use the CLI instead
85-
- name: 'Attach the Ingress floating IP to Ingress port'
86-
ansible.builtin.command:
87-
cmd: "openstack floating ip set --port {{ os_port_ingress }} {{ os_ingress_fip }}"
88-
when: os_ingress_fip is defined and os_ingress_fip|length>0
131+
- name: 'Populate inventory with Ingress addresses'
132+
shell: |
133+
python -c 'import yaml
134+
path = "inventory.yaml"
135+
ipv4 = "{{ item.ip_address|ansible.utils.ipv4 }}"
136+
ipv6 = "{{ item.ip_address|ansible.utils.ipv6 }}"
137+
if ipv4 != "False":
138+
key = "os_ingressVIP"
139+
ip = ipv4
140+
else:
141+
key = "os_ingressVIP6"
142+
ip = ipv6
143+
data = yaml.safe_load(open(path))
144+
data["all"]["hosts"]["localhost"][key] = ip
145+
open(path, "w").write(yaml.dump(data, default_flow_style=False))'
146+
when:
147+
- ingress_ports.port is defined
148+
loop: "{{ ingress_ports.port.fixed_ips }}"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Required Python packages:
2+
#
3+
# ansible
4+
# openstackclient
5+
# openstacksdk
6+
# netaddr
7+
8+
- ansible.builtin.import_playbook: common.yaml
9+
10+
- hosts: all
11+
gather_facts: no
12+
13+
tasks:
14+
- name: 'Set tags on the primary cluster network'
15+
ansible.builtin.command:
16+
cmd: "openstack network set --tag {{ primary_cluster_network_tag }} --tag {{ cluster_id_tag }} {{ os_network }}"
17+
18+
- name: 'Set tags on primary cluster subnet IPv4'
19+
ansible.builtin.command:
20+
cmd: "openstack subnet set --tag {{ cluster_id_tag }} {{ os_subnet }}"
21+
22+
- name: 'Set tags on primary cluster subnet IPv6'
23+
ansible.builtin.command:
24+
cmd: "openstack subnet set --tag {{ cluster_id_tag }} {{ os_subnet6 }}"
25+
when:
26+
- os_subnet6_range is defined
27+
- os_subnet6_range|ansible.utils.ipv6
28+
29+
- name: 'Set tags on the API VIP port'
30+
ansible.builtin.command:
31+
cmd: "openstack port set --tag {{ cluster_id_tag }} {{ os_port_api }}"
32+
33+
- name: 'Set tags on the Ingress VIP port'
34+
ansible.builtin.command:
35+
cmd: "openstack port set --tag {{ cluster_id_tag }} {{ os_port_ingress }}"
36+
37+
- name: 'Set external router tag'
38+
ansible.builtin.command:
39+
cmd: "openstack router set --tag {{ cluster_id_tag }} {{ os_router }}"
40+
when: os_external_network is defined and os_external_network|length>0
41+
42+
# NOTE: openstack ansible module doesn't allow attaching Floating IPs to
43+
# ports, let's use the CLI instead
44+
- name: 'Attach the API floating IP to API port'
45+
ansible.builtin.command:
46+
cmd: "openstack floating ip set --port {{ os_port_api }} {{ os_api_fip }}"
47+
when: os_api_fip is defined and os_api_fip|length>0
48+
49+
# NOTE: openstack ansible module doesn't allow attaching Floating IPs to
50+
# ports, let's use the CLI instead
51+
- name: 'Attach the Ingress floating IP to Ingress port'
52+
ansible.builtin.command:
53+
cmd: "openstack floating ip set --port {{ os_port_ingress }} {{ os_ingress_fip }}"
54+
when: os_ingress_fip is defined and os_ingress_fip|length>0
55+
56+
- name: 'Set security group to api port'
57+
ansible.builtin.command:
58+
cmd: "openstack port set --security-group {{ os_sg_master }} {{ os_port_api }}"
59+
60+
- name: 'Set security group to ingress port'
61+
ansible.builtin.command:
62+
cmd: "openstack port set --security-group {{ os_sg_worker }} {{ os_port_ingress }}"

0 commit comments

Comments
 (0)