mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 10:00:01 -03:30
updated projects to use notifications
This commit is contained in:
parent
23a20b9db0
commit
b3323a24e4
@ -127,6 +127,21 @@ 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_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
|
||||
extends_documentation_fragment: awx.awx.auth
|
||||
'''
|
||||
|
||||
@ -194,6 +209,9 @@ def main():
|
||||
job_timeout=dict(type='int', default=0),
|
||||
custom_virtualenv=dict(),
|
||||
organization=dict(required=True),
|
||||
notification_templates_started=dict(type="list", elements='str'),
|
||||
notification_templates_success=dict(type="list", elements='str'),
|
||||
notification_templates_error=dict(type="list", elements='str'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
wait=dict(type='bool', default=True),
|
||||
)
|
||||
@ -240,6 +258,27 @@ 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(project)
|
||||
|
||||
# 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))
|
||||
|
||||
# Create the data that gets sent for create and update
|
||||
project_fields = {
|
||||
'name': name,
|
||||
@ -274,7 +313,12 @@ def main():
|
||||
on_change = wait_for_project_update
|
||||
|
||||
# If the state was present and we can let the module build or update the existing project, this will return on its own
|
||||
module.create_or_update_if_needed(project, project_fields, endpoint='projects', item_type='project', on_create=on_change, on_update=on_change)
|
||||
module.create_or_update_if_needed(
|
||||
project, project_fields,
|
||||
endpoint='projects', item_type='project',
|
||||
associations=association_fields,
|
||||
on_create=on_change, on_update=on_change
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user