mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-03-26 21:43:02 +00:00
As per the REST Networking API v2.0 (Subnet) docs, if subnets pools are not specified, OpenStack networking automatically allocates pools covering all IP addresses in the CIDR. In custom vendor specific environments, subnets can be created without allocation pools via UI due to which subnets will not have any existing allocation pools. Under this scenario, module throws an "IndexError: list index out of range" error. Also, allow to add more allocation pools on top of existing allocation pools. Change-Id: Ib8becf5e958f1bc8e5c9fd76f1722536bf1c9f1a
64 lines
1.9 KiB
YAML
64 lines
1.9 KiB
YAML
---
|
|
- name: Create network {{ network_name }}
|
|
openstack.cloud.os_network:
|
|
cloud: "{{ cloud }}"
|
|
name: "{{ network_name }}"
|
|
state: present
|
|
|
|
- name: Create subnet {{ subnet_name }} on network {{ network_name }}
|
|
openstack.cloud.os_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
|
|
|
|
- name: Update subnet {{ subnet_name }} allocation pools
|
|
openstack.cloud.os_subnet:
|
|
cloud: "{{ cloud }}"
|
|
network_name: "{{ network_name }}"
|
|
name: "{{ subnet_name }}"
|
|
state: present
|
|
cidr: 192.168.0.0/24
|
|
allocation_pool_start: 192.168.0.5
|
|
allocation_pool_end: 192.168.0.8
|
|
|
|
- name: Get Subnet Info
|
|
openstack.cloud.os_subnets_info:
|
|
cloud: "{{ cloud }}"
|
|
name: "{{ subnet_name }}"
|
|
register: subnet_result
|
|
|
|
- name: Verify Subnet Allocation Pools Exist
|
|
assert:
|
|
that:
|
|
- 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
|
|
|
|
- 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'}
|
|
|
|
- name: Delete subnet {{ subnet_name }}
|
|
openstack.cloud.os_subnet:
|
|
cloud: "{{ cloud }}"
|
|
name: "{{ subnet_name }}"
|
|
state: absent
|
|
|
|
- name: Delete network {{ network_name }}
|
|
openstack.cloud.os_network:
|
|
cloud: "{{ cloud }}"
|
|
name: "{{ network_name }}"
|
|
state: absent
|