mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 22:34:12 +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_start: 192.168.0.2
|
||||||
allocation_pool_end: 192.168.0.4
|
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
|
- name: Update subnet {{ subnet_name }} allocation pools
|
||||||
openstack.cloud.subnet:
|
openstack.cloud.subnet:
|
||||||
cloud: "{{ cloud }}"
|
cloud: "{{ cloud }}"
|
||||||
@@ -24,7 +37,7 @@
|
|||||||
name: "{{ subnet_name }}"
|
name: "{{ subnet_name }}"
|
||||||
state: present
|
state: present
|
||||||
cidr: 192.168.0.0/24
|
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
|
allocation_pool_end: 192.168.0.8
|
||||||
|
|
||||||
- name: Get Subnet Info
|
- name: Get Subnet Info
|
||||||
@@ -36,19 +49,17 @@
|
|||||||
- name: Verify Subnet Allocation Pools Exist
|
- name: Verify Subnet Allocation Pools Exist
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
- idem1 is not changed
|
||||||
- subnet_result.openstack_subnets is defined
|
- subnet_result.openstack_subnets is defined
|
||||||
- subnet_result.openstack_subnets | length == 1
|
- subnet_result.openstack_subnets | length == 1
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools is defined
|
- 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
|
- name: Verify Subnet Allocation Pools
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools | selectattr('start','equalto',item.start) | list | count > 0
|
- subnet_result.openstack_subnets[0].allocation_pools.0.start == '192.168.0.2'
|
||||||
- subnet_result.openstack_subnets[0].allocation_pools | selectattr('end','equalto',item.end) | list | count > 0
|
- subnet_result.openstack_subnets[0].allocation_pools.0.end == '192.168.0.8'
|
||||||
loop:
|
|
||||||
- {start: '192.168.0.2', end: '192.168.0.4'}
|
|
||||||
- {start: '192.168.0.5', end: '192.168.0.8'}
|
|
||||||
|
|
||||||
- name: Delete subnet {{ subnet_name }}
|
- name: Delete subnet {{ subnet_name }}
|
||||||
openstack.cloud.subnet:
|
openstack.cloud.subnet:
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ def _needs_update(subnet, module, cloud, filters=None):
|
|||||||
return True
|
return True
|
||||||
if not subnet['allocation_pools'] and pool_start and pool_end:
|
if not subnet['allocation_pools'] and pool_start and pool_end:
|
||||||
return True
|
return True
|
||||||
if subnet['allocation_pools'] and curr_pool not in subnet['allocation_pools']:
|
if subnet['allocation_pools'] != [curr_pool]:
|
||||||
return True
|
return True
|
||||||
if gateway_ip and subnet['gateway_ip'] != gateway_ip:
|
if gateway_ip and subnet['gateway_ip'] != gateway_ip:
|
||||||
return True
|
return True
|
||||||
@@ -346,16 +346,14 @@ def main():
|
|||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
if _needs_update(subnet, module, cloud, filters):
|
if _needs_update(subnet, module, cloud, filters):
|
||||||
if subnet['allocation_pools'] and pool is not None:
|
subnet = cloud.update_subnet(subnet['id'],
|
||||||
pool = pool + subnet['allocation_pools']
|
subnet_name=subnet_name,
|
||||||
cloud.update_subnet(subnet['id'],
|
enable_dhcp=enable_dhcp,
|
||||||
subnet_name=subnet_name,
|
gateway_ip=gateway_ip,
|
||||||
enable_dhcp=enable_dhcp,
|
disable_gateway_ip=no_gateway_ip,
|
||||||
gateway_ip=gateway_ip,
|
dns_nameservers=dns,
|
||||||
disable_gateway_ip=no_gateway_ip,
|
allocation_pools=pool,
|
||||||
dns_nameservers=dns,
|
host_routes=host_routes)
|
||||||
allocation_pools=pool,
|
|
||||||
host_routes=host_routes)
|
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
|
|||||||
Reference in New Issue
Block a user