mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-03-26 21:43:02 +00:00
Merge "Fix subnets update and idempotency"
This commit is contained in:
@@ -17,6 +17,19 @@
|
||||
allocation_pool_start: 192.168.0.2
|
||||
allocation_pool_end: 192.168.0.4
|
||||
|
||||
- name: Create subnet {{ subnet_name }} on network {{ network_name }} again
|
||||
openstack.cloud.subnet:
|
||||
cloud: "{{ cloud }}"
|
||||
network_name: "{{ network_name }}"
|
||||
enable_dhcp: "{{ enable_subnet_dhcp }}"
|
||||
name: "{{ subnet_name }}"
|
||||
state: present
|
||||
cidr: 192.168.0.0/24
|
||||
gateway_ip: 192.168.0.1
|
||||
allocation_pool_start: 192.168.0.2
|
||||
allocation_pool_end: 192.168.0.4
|
||||
register: idem1
|
||||
|
||||
- name: Update subnet {{ subnet_name }} allocation pools
|
||||
openstack.cloud.subnet:
|
||||
cloud: "{{ cloud }}"
|
||||
@@ -24,7 +37,7 @@
|
||||
name: "{{ subnet_name }}"
|
||||
state: present
|
||||
cidr: 192.168.0.0/24
|
||||
allocation_pool_start: 192.168.0.5
|
||||
allocation_pool_start: 192.168.0.2
|
||||
allocation_pool_end: 192.168.0.8
|
||||
|
||||
- name: Get Subnet Info
|
||||
@@ -36,19 +49,17 @@
|
||||
- name: Verify Subnet Allocation Pools Exist
|
||||
assert:
|
||||
that:
|
||||
- idem1 is not changed
|
||||
- subnet_result.openstack_subnets is defined
|
||||
- subnet_result.openstack_subnets | length == 1
|
||||
- subnet_result.openstack_subnets[0].allocation_pools is defined
|
||||
- subnet_result.openstack_subnets[0].allocation_pools | length == 2
|
||||
- subnet_result.openstack_subnets[0].allocation_pools | length == 1
|
||||
|
||||
- name: Verify Subnet Allocation Pools
|
||||
assert:
|
||||
that:
|
||||
- subnet_result.openstack_subnets[0].allocation_pools | selectattr('start','equalto',item.start) | list | count > 0
|
||||
- subnet_result.openstack_subnets[0].allocation_pools | selectattr('end','equalto',item.end) | list | count > 0
|
||||
loop:
|
||||
- {start: '192.168.0.2', end: '192.168.0.4'}
|
||||
- {start: '192.168.0.5', end: '192.168.0.8'}
|
||||
- subnet_result.openstack_subnets[0].allocation_pools.0.start == '192.168.0.2'
|
||||
- subnet_result.openstack_subnets[0].allocation_pools.0.end == '192.168.0.8'
|
||||
|
||||
- name: Delete subnet {{ subnet_name }}
|
||||
openstack.cloud.subnet:
|
||||
|
||||
@@ -207,7 +207,7 @@ def _needs_update(subnet, module, cloud, filters=None):
|
||||
return True
|
||||
if not subnet['allocation_pools'] and pool_start and pool_end:
|
||||
return True
|
||||
if subnet['allocation_pools'] and curr_pool not in subnet['allocation_pools']:
|
||||
if subnet['allocation_pools'] != [curr_pool]:
|
||||
return True
|
||||
if gateway_ip and subnet['gateway_ip'] != gateway_ip:
|
||||
return True
|
||||
@@ -346,16 +346,14 @@ def main():
|
||||
changed = True
|
||||
else:
|
||||
if _needs_update(subnet, module, cloud, filters):
|
||||
if subnet['allocation_pools'] and pool is not None:
|
||||
pool = pool + subnet['allocation_pools']
|
||||
cloud.update_subnet(subnet['id'],
|
||||
subnet_name=subnet_name,
|
||||
enable_dhcp=enable_dhcp,
|
||||
gateway_ip=gateway_ip,
|
||||
disable_gateway_ip=no_gateway_ip,
|
||||
dns_nameservers=dns,
|
||||
allocation_pools=pool,
|
||||
host_routes=host_routes)
|
||||
subnet = cloud.update_subnet(subnet['id'],
|
||||
subnet_name=subnet_name,
|
||||
enable_dhcp=enable_dhcp,
|
||||
gateway_ip=gateway_ip,
|
||||
disable_gateway_ip=no_gateway_ip,
|
||||
dns_nameservers=dns,
|
||||
allocation_pools=pool,
|
||||
host_routes=host_routes)
|
||||
changed = True
|
||||
else:
|
||||
changed = False
|
||||
|
||||
Reference in New Issue
Block a user