Skip to content

Commit f2654d5

Browse files
skip openstack subnet pool creation when prefixes tagged openstack-subnet-pool not found
1 parent 98e3936 commit f2654d5

2 files changed

Lines changed: 47 additions & 43 deletions

File tree

ansible/roles/openstack_subnet_pools/tasks/main.yml

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -24,50 +24,54 @@
2424
ansible.builtin.debug:
2525
msg: "Found {{ prefixes_query.json.count }} prefixes tagged with '{{ subnet_pool_tag }}' in location '{{ site_location }}'"
2626

27-
- name: Assert prefixes were found
28-
ansible.builtin.assert:
29-
that:
30-
- prefixes_query.json.count > 0
31-
fail_msg: "No prefixes found with tag '{{ subnet_pool_tag }}' in location '{{ site_location }}' in Nautobot"
27+
- name: Skip subnet pool creation when no prefixes were found
28+
ansible.builtin.debug:
29+
msg: >-
30+
No prefixes found with tag '{{ subnet_pool_tag }}' in location
31+
'{{ site_location }}'; skipping OpenStack subnet pool creation
32+
when: prefixes_query.json.count | int == 0
3233

33-
- name: Group prefixes by subnet pool name
34-
ansible.builtin.set_fact:
35-
subnet_pools: |
36-
{{
37-
prefixes_query.json.results
38-
| selectattr('custom_fields.subnet_pool_name', 'defined')
39-
| groupby('custom_fields.subnet_pool_name')
40-
| map(attribute='1')
41-
| map('list')
42-
}}
34+
- name: Create OpenStack subnet pools from matching prefixes
35+
when: prefixes_query.json.count | int > 0
36+
block:
37+
- name: Group prefixes by subnet pool name
38+
ansible.builtin.set_fact:
39+
subnet_pools: |
40+
{{
41+
prefixes_query.json.results
42+
| selectattr('custom_fields.subnet_pool_name', 'defined')
43+
| groupby('custom_fields.subnet_pool_name')
44+
| map(attribute='1')
45+
| map('list')
46+
}}
4347
44-
- name: Log discovered subnet pools
45-
ansible.builtin.debug:
46-
msg: |
47-
Discovered subnet pools:
48-
{{ subnet_pools | map(attribute='0.custom_fields.subnet_pool_name') | list }}
48+
- name: Log discovered subnet pools
49+
ansible.builtin.debug:
50+
msg: |
51+
Discovered subnet pools:
52+
{{ subnet_pools | map(attribute='0.custom_fields.subnet_pool_name') | list }}
4953
50-
- name: Create or update OpenStack subnet pools
51-
openstack.cloud.subnet_pool:
52-
state: present
53-
name: "{{ pool_item[0].custom_fields.subnet_pool_name }}"
54-
prefixes: "{{ pool_item | map(attribute='prefix') | list }}"
55-
default_prefix_length: "{{ pool_item[0].custom_fields.subnet_pool_default_prefixlen }}"
56-
minimum_prefix_length: "{{ pool_item[0].custom_fields.subnet_pool_min_prefixlen }}"
57-
maximum_prefix_length: "{{ pool_item[0].custom_fields.subnet_pool_max_prefixlen }}"
58-
is_shared: true
59-
loop: "{{ subnet_pools }}"
60-
loop_control:
61-
loop_var: pool_item
62-
label: "{{ pool_item[0].custom_fields.subnet_pool_name }}"
63-
register: subnet_pool_results
54+
- name: Create or update OpenStack subnet pools
55+
openstack.cloud.subnet_pool:
56+
state: present
57+
name: "{{ pool_item[0].custom_fields.subnet_pool_name }}"
58+
prefixes: "{{ pool_item | map(attribute='prefix') | list }}"
59+
default_prefix_length: "{{ pool_item[0].custom_fields.subnet_pool_default_prefixlen }}"
60+
minimum_prefix_length: "{{ pool_item[0].custom_fields.subnet_pool_min_prefixlen }}"
61+
maximum_prefix_length: "{{ pool_item[0].custom_fields.subnet_pool_max_prefixlen }}"
62+
is_shared: true
63+
loop: "{{ subnet_pools }}"
64+
loop_control:
65+
loop_var: pool_item
66+
label: "{{ pool_item[0].custom_fields.subnet_pool_name }}"
67+
register: subnet_pool_results
6468

65-
- name: Log subnet pool creation results
66-
ansible.builtin.debug:
67-
msg: "Subnet pool '{{ item.pool_item[0].custom_fields.subnet_pool_name }}': {{ 'created' if item is changed else 'unchanged' }}"
68-
loop: "{{ subnet_pool_results.results }}"
69-
when: item is not skipped
69+
- name: Log subnet pool creation results
70+
ansible.builtin.debug:
71+
msg: "Subnet pool '{{ item.pool_item[0].custom_fields.subnet_pool_name }}': {{ 'created' if item is changed else 'unchanged' }}"
72+
loop: "{{ subnet_pool_results.results }}"
73+
when: item is not skipped
7074

71-
- name: Verify subnet pools were created
72-
ansible.builtin.debug:
73-
msg: "Successfully created/updated {{ subnet_pool_results.results | length }} subnet pools"
75+
- name: Verify subnet pools were created
76+
ansible.builtin.debug:
77+
msg: "Successfully created/updated {{ subnet_pool_results.results | length }} subnet pools"

components/neutron/job-neutron-post-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
type: RuntimeDefault
2424
containers:
2525
- name: ansible
26-
image: ghcr.io/rackerlabs/understack/ansible:latest
26+
image: ghcr.io/rackerlabs/understack/ansible:pr-2146
2727
imagePullPolicy: Always
2828
command: ["ansible-runner", "run", "/runner", "--playbook", "neutron-post-deploy.yaml"]
2929
resources:

0 commit comments

Comments
 (0)