From ca0130fc649de7fa982df742067850ee67f6a09b Mon Sep 17 00:00:00 2001 From: excalibrax Date: Wed, 13 May 2020 20:33:23 -0500 Subject: [PATCH] update organizations and approvals --- .../plugins/modules/tower_organization.py | 61 ++++++++++++++++++- .../modules/tower_workflow_job_template.py | 12 ++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/awx_collection/plugins/modules/tower_organization.py b/awx_collection/plugins/modules/tower_organization.py index 44bb47c787..5fb845afeb 100644 --- a/awx_collection/plugins/modules/tower_organization.py +++ b/awx_collection/plugins/modules/tower_organization.py @@ -56,6 +56,31 @@ options: - If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files type: str version_added: "3.7" + notification_templates_approvals: + description: + - list of notifications to send on start + type: list + elements: str + notification_templates_started: + description: + - list of notifications to send on start + type: list + elements: str + notification_templates_success: + description: + - list of notifications to send on success + type: list + elements: str + notification_templates_error: + description: + - list of notifications to send on error + type: list + elements: str + notification_templates_approvals: + description: + - list of notifications to send on start + type: list + elements: str extends_documentation_fragment: awx.awx.auth ''' @@ -87,6 +112,10 @@ def main(): description=dict(), custom_virtualenv=dict(), max_hosts=dict(type='int', default="0"), + notification_templates_started=dict(type="list", elements='str'), + notification_templates_success=dict(type="list", elements='str'), + notification_templates_error=dict(type="list", elements='str'), + notification_templates_approvals=dict(type="list", elements='str'), state=dict(choices=['present', 'absent'], default='present'), ) @@ -111,6 +140,32 @@ def main(): if state == 'absent': # 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(organization) + # Attempt to look up associated field items the user specified. + association_fields = {} + + notifications_start = module.params.get('notification_templates_started') + if notifications_start is not None: + association_fields['notification_templates_started'] = [] + for item in notifications_start: + association_fields['notification_templates_started'].append(module.resolve_name_to_id('notification_templates', item)) + + notifications_success = module.params.get('notification_templates_success') + if notifications_success is not None: + association_fields['notification_templates_success'] = [] + for item in notifications_success: + association_fields['notification_templates_success'].append(module.resolve_name_to_id('notification_templates', item)) + + notifications_error = module.params.get('notification_templates_error') + if notifications_error is not None: + association_fields['notification_templates_error'] = [] + for item in notifications_error: + association_fields['notification_templates_error'].append(module.resolve_name_to_id('notification_templates', item)) + + notifications_approval = module.params.get('notification_templates_approvals') + if notifications_approval is not None: + association_fields['notification_templates_approvals'] = [] + for item in notifications_approval: + association_fields['notification_templates_approvals'].append(module.resolve_name_to_id('notification_templates', item)) # Create the data that gets sent for create and update org_fields = {'name': name} @@ -122,7 +177,11 @@ def main(): org_fields['max_hosts'] = max_hosts # If the state was present and we can let the module build or update the existing organization, this will return on its own - module.create_or_update_if_needed(organization, org_fields, endpoint='organizations', item_type='organization') + module.create_or_update_if_needed( + organization, org_fields, + endpoint='organizations', item_type='organization' + associations=association_fields, + ) if __name__ == '__main__': diff --git a/awx_collection/plugins/modules/tower_workflow_job_template.py b/awx_collection/plugins/modules/tower_workflow_job_template.py index e130d02cf1..825e0018ba 100644 --- a/awx_collection/plugins/modules/tower_workflow_job_template.py +++ b/awx_collection/plugins/modules/tower_workflow_job_template.py @@ -128,6 +128,11 @@ options: - list of notifications to send on error type: list elements: str + notification_templates_approvals: + description: + - list of notifications to send on start + type: list + elements: str extends_documentation_fragment: awx.awx.auth ''' @@ -173,6 +178,7 @@ def main(): notification_templates_started=dict(type="list", elements='str'), notification_templates_success=dict(type="list", elements='str'), notification_templates_error=dict(type="list", elements='str'), + notification_templates_approvals=dict(type="list", elements='str'), state=dict(choices=['present', 'absent'], default='present'), ) @@ -242,6 +248,12 @@ def main(): for item in notifications_error: association_fields['notification_templates_error'].append(module.resolve_name_to_id('notification_templates', item)) + notifications_approval = module.params.get('notification_templates_approvals') + if notifications_approval is not None: + association_fields['notification_templates_approvals'] = [] + for item in notifications_approval: + association_fields['notification_templates_approvals'].append(module.resolve_name_to_id('notification_templates', item)) + on_change = None new_spec = module.params.get('survey') if new_spec: