Skip to content

Commit

Permalink
don't pass the 'organization' or other fields to the search of the in…
Browse files Browse the repository at this point in the history
…stance group or execution environments (ansible#14223)
  • Loading branch information
ivarmu authored and djyasin committed Sep 11, 2024
1 parent 6d27772 commit 7ce2ae3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
38 changes: 23 additions & 15 deletions awx_collection/plugins/modules/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,36 @@ def main():
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
module.delete_if_needed(existing_item)

# We need to clear out the name from the search fields so we can use name_or_id in the following searches
if 'name' in search_fields:
del search_fields['name']

# Create the data that gets sent for create and update
new_fields = {}
if execution_environment is not None:
if execution_environment == '':
new_fields['execution_environment'] = ''
else:
ee = module.get_one('execution_environments', name_or_id=execution_environment, **{'data': search_fields})
if ee is None:
ee2 = module.get_one('execution_environments', name_or_id=execution_environment)
if ee2 is None or ee2['organization'] is not None:
module.fail_json(msg='could not find execution_environment entry with name {0}'.format(execution_environment))
else:
new_fields['execution_environment'] = ee2['id']
else:
new_fields['execution_environment'] = ee['id']

association_fields = {}

if credentials is not None:
association_fields['credentials'] = []
for item in credentials:
association_fields['credentials'].append(module.resolve_name_to_id('credentials', item))

# We need to clear out the name from the search fields so we can use name_or_id in the following searches
if 'name' in search_fields:
del search_fields['name']
# We need to clear out the organization from the search fields the searches for labels and instance_groups doesnt support it and won't be needed anymore
if 'organization' in search_fields:
del search_fields['organization']

if labels is not None:
association_fields['labels'] = []
Expand All @@ -302,8 +322,6 @@ def main():
else:
association_fields['instance_groups'].append(instance_group_id['id'])

# Create the data that gets sent for create and update
new_fields = {}
if rrule is not None:
new_fields['rrule'] = rrule
new_fields['name'] = new_name if new_name else (module.get_item_name(existing_item) if existing_item else name)
Expand Down Expand Up @@ -338,16 +356,6 @@ def main():
if timeout is not None:
new_fields['timeout'] = timeout

if execution_environment is not None:
if execution_environment == '':
new_fields['execution_environment'] = ''
else:
ee = module.get_one('execution_environments', name_or_id=execution_environment, **{'data': search_fields})
if ee is None:
module.fail_json(msg='could not find execution_environment entry with name {0}'.format(execution_environment))
else:
new_fields['execution_environment'] = ee['id']

# If the state was present and we can let the module build or update the existing item, this will return on its own
module.create_or_update_if_needed(
existing_item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
schedule:
name: "{{ sched2 }}"
state: present
organization: Default
unified_job_template: "{{ jt1 }}"
rrule: "DTSTART:20191219T130551Z RRULE:FREQ=WEEKLY;INTERVAL=1;COUNT=1"
description: "This hopefully will work"
Expand Down

0 comments on commit 7ce2ae3

Please sign in to comment.