1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-27 09:25:10 +03:00

Support adding/removing notifications to job_templates

This commit is contained in:
Francois Herbert 2020-04-20 13:02:41 +12:00
parent 8f5afc83ce
commit 68a0bbe125
2 changed files with 93 additions and 0 deletions

View File

@ -275,6 +275,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
@ -365,6 +380,9 @@ def main():
webhook_service=dict(choices=['github', 'gitlab']),
webhook_credential=dict(),
labels=dict(type="list", elements='str'),
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'),
)
@ -441,6 +459,24 @@ def main():
for item in labels:
labels_ids.append(module.resolve_name_to_id('labels', item))
notifications_start = module.params.get('notification_templates_started')
notification_start_ids = []
if notifications_start is not None:
for item in notifications_start:
notification_start_ids.append(module.resolve_name_to_id('notification_templates', item))
notifications_success = module.params.get('notification_templates_success')
notification_success_ids = []
if notifications_success is not None:
for item in notifications_success:
notification_success_ids.append(module.resolve_name_to_id('notification_templates', item))
notifications_error = module.params.get('notification_templates_error')
notification_error_ids = []
if notifications_error is not None:
for item in notifications_error:
notification_error_ids.append(module.resolve_name_to_id('notification_templates', item))
on_change = None
new_spec = module.params.get('survey_spec')
if new_spec is not None:
@ -465,6 +501,9 @@ def main():
associations={
'credentials': credentials_ids,
'labels': labels_ids,
'notification_templates_success': notification_success_ids,
'notification_templates_started': notification_start_ids,
'notification_templates_error': notification_error_ids
},
on_create=on_change, on_update=on_change,
)

View File

@ -12,6 +12,7 @@
jt1: "AWX-Collection-tests-tower_job_template-jt1-{{ test_id }}"
jt2: "AWX-Collection-tests-tower_job_template-jt2-{{ test_id }}"
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ test_id }}"
email_not: "AWX-Collection-tests-tower_job_template-email-not-{{ test_id }}"
- name: Create a Demo Project
tower_project:
@ -46,6 +47,22 @@
name: "{{ lab1 }}"
organization: Default
- name: Add email notification
tower_notification:
name: "{{ email_not }}"
organization: Default
notification_type: email
username: user
password: s3cr3t
sender: tower@example.com
recipients:
- user1@example.com
host: smtp.example.com
port: 25
use_tls: false
use_ssl: false
state: present
- name: Create Job Template 1
tower_job_template:
name: "{{ jt1 }}"
@ -240,6 +257,37 @@
that:
- "result is changed"
- name: Add started notification to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
notification_templates_started:
- "{{ email_not }}"
register: result
- assert:
that:
- "result is changed"
- name: Re Add started notification to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
notification_templates_started:
- "{{ email_not }}"
register: result
- assert:
that:
- "result is not changed"
- name: Remove started notification to Job Template 2
tower_job_template:
name: "{{ jt2 }}"
register: result
- assert:
that:
- "result is changed"
- name: Delete Job Template 2
tower_job_template:
name: "{{ jt2 }}"
@ -286,3 +334,9 @@
state: absent
# You can't delete a label directly so no cleanup needed
- name: Delete email notification
tower_notification:
name: "{{ email_not }}"
organization: Default
state: absent