summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--awx_collection/plugins/modules/schedule.py38
-rw-r--r--awx_collection/tests/integration/targets/schedule/tasks/main.yml1
2 files changed, 24 insertions, 15 deletions
diff --git a/awx_collection/plugins/modules/schedule.py b/awx_collection/plugins/modules/schedule.py
index 5e64a3b8f5..4a6583629d 100644
--- a/awx_collection/plugins/modules/schedule.py
+++ b/awx_collection/plugins/modules/schedule.py
@@ -273,6 +273,26 @@ 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:
@@ -280,9 +300,9 @@ def main():
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'] = []
@@ -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)
@@ -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,
diff --git a/awx_collection/tests/integration/targets/schedule/tasks/main.yml b/awx_collection/tests/integration/targets/schedule/tasks/main.yml
index b02c7f72dd..df7e2d88e3 100644
--- a/awx_collection/tests/integration/targets/schedule/tasks/main.yml
+++ b/awx_collection/tests/integration/targets/schedule/tasks/main.yml
@@ -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"