|
5 | 5 | # openstacksdk |
6 | 6 | # netaddr |
7 | 7 |
|
8 | | -- ansible.builtin.import_playbook: common.yaml |
9 | | - |
10 | 8 | - hosts: all |
11 | 9 | gather_facts: no |
12 | 10 |
|
13 | 11 | tasks: |
14 | | - - name: 'Create the primary cluster network' |
| 12 | + - name: 'Create the cluster network' |
15 | 13 | openstack.cloud.network: |
16 | 14 | name: "{{ os_network }}" |
17 | 15 |
|
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' |
23 | 17 | openstack.cloud.subnet: |
24 | 18 | name: "{{ os_subnet }}" |
25 | 19 | network_name: "{{ os_network }}" |
|
28 | 22 | allocation_pool_end: "{{ os_subnet_range | ansible.utils.ipaddr('last_usable') }}" |
29 | 23 | dns_nameservers: "{{ os_external_dns }}" |
30 | 24 |
|
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 |
34 | 36 |
|
35 | 37 | - name: 'Create external router' |
36 | 38 | openstack.cloud.router: |
|
40 | 42 | - "{{ os_subnet }}" |
41 | 43 | when: os_external_network is defined and os_external_network|length>0 |
42 | 44 |
|
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 |
47 | 55 |
|
48 | 56 | - name: 'Create the API port' |
49 | 57 | openstack.cloud.port: |
50 | 58 | name: "{{ os_port_api }}" |
51 | 59 | network: "{{ os_network }}" |
52 | | - security_groups: |
53 | | - - "{{ os_sg_master }}" |
54 | 60 | fixed_ips: |
55 | 61 | - subnet: "{{ os_subnet }}" |
56 | 62 | ip_address: "{{ os_apiVIP }}" |
| 63 | + register: _api_ports |
| 64 | + when: |
| 65 | + - os_subnet6_range is not defined |
57 | 66 |
|
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 |
61 | 83 |
|
62 | 84 | - name: 'Create the Ingress port' |
63 | 85 | openstack.cloud.port: |
64 | 86 | name: "{{ os_port_ingress }}" |
65 | 87 | network: "{{ os_network }}" |
66 | | - security_groups: |
67 | | - - "{{ os_sg_worker }}" |
68 | 88 | fixed_ips: |
69 | 89 | - subnet: "{{ os_subnet }}" |
70 | 90 | 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 }}" |
71 | 130 |
|
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 }}" |
0 commit comments