Skip to content

Commit eb96d5d

Browse files
fix chicken egg issue with workflow nodes and inventory sources for parents that do not exist (ansible#15982)
fix chicken egg issue with workflow nodes and inventory sources for parents that do not exist
1 parent 94764a1 commit eb96d5d

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

awx_collection/plugins/modules/inventory_source.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ def main():
230230
inventory_object = module.get_one('inventories', name_or_id=inventory, data=lookup_data)
231231

232232
if not inventory_object:
233-
module.fail_json(msg='The specified inventory, {0}, was not found.'.format(lookup_data))
233+
# if the inventory does not exist, then it can't have sources.
234+
if state == 'absent':
235+
module.exit_json(**module.json_output)
236+
else:
237+
module.fail_json(msg='The specified inventory, {0}, was not found.'.format(lookup_data))
234238

235239
inventory_source_object = module.get_one(
236240
'inventory_sources',

awx_collection/plugins/modules/workflow_job_template_node.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,13 @@ def main():
320320
wfjt_search_fields['organization'] = organization_id
321321
wfjt_data = module.get_one('workflow_job_templates', name_or_id=workflow_job_template, **{'data': wfjt_search_fields})
322322
if wfjt_data is None:
323-
module.fail_json(
324-
msg="The workflow {0} in organization {1} was not found on the controller instance server".format(workflow_job_template, organization)
325-
)
323+
if state == 'absent':
324+
# if the workflow doesn't exist, it can't have workflow nodes.
325+
module.exit_json(**module.json_output)
326+
else:
327+
module.fail_json(
328+
msg="The workflow {0} in organization {1} was not found on the controller instance server".format(workflow_job_template, organization)
329+
)
326330
workflow_job_template_id = wfjt_data['id']
327331
search_fields['workflow_job_template'] = new_fields['workflow_job_template'] = workflow_job_template_id
328332

awx_collection/tests/integration/targets/inventory_source_update/tasks/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@
121121
that:
122122
- "result is changed"
123123

124+
- name: Attempt to delete an inventory source from an inventory that does not exist
125+
inventory_source:
126+
name: "{{ inv_source3 }}"
127+
source: scm
128+
state: absent
129+
source_project: "{{ project_name }}"
130+
source_path: inventories/create_100_hosts.ini
131+
description: Source for Test inventory
132+
organization: Default
133+
inventory: Does not exist
134+
register: result
135+
136+
- assert:
137+
that:
138+
- "result is not changed"
139+
124140
always:
125141
- name: Delete Inventory
126142
inventory:

awx_collection/tests/integration/targets/workflow_job_template/tasks/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@
428428
that:
429429
- "results is changed"
430430

431+
- name: Remove a node from a workflow that does not exist.
432+
workflow_job_template_node:
433+
identifier: root
434+
unified_job_template: "{{ jt1_name }}"
435+
workflow: Does not exist
436+
state: absent
437+
register: results
438+
439+
- assert:
440+
that:
441+
- "results is not changed"
442+
431443
- name: Create root node
432444
workflow_job_template_node:
433445
identifier: root

0 commit comments

Comments
 (0)