mirror of
https://github.com/ansible/awx.git
synced 2026-04-04 17:55:06 -02:30
Support adding/removing notifications to job_templates
This commit is contained in:
@@ -275,6 +275,21 @@ options:
|
|||||||
- If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files
|
- If value not set, will try environment variable C(TOWER_OAUTH_TOKEN) and then config files
|
||||||
type: str
|
type: str
|
||||||
version_added: "3.7"
|
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
|
extends_documentation_fragment: awx.awx.auth
|
||||||
|
|
||||||
@@ -365,6 +380,9 @@ def main():
|
|||||||
webhook_service=dict(choices=['github', 'gitlab']),
|
webhook_service=dict(choices=['github', 'gitlab']),
|
||||||
webhook_credential=dict(),
|
webhook_credential=dict(),
|
||||||
labels=dict(type="list", elements='str'),
|
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'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -441,6 +459,24 @@ def main():
|
|||||||
for item in labels:
|
for item in labels:
|
||||||
labels_ids.append(module.resolve_name_to_id('labels', item))
|
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
|
on_change = None
|
||||||
new_spec = module.params.get('survey_spec')
|
new_spec = module.params.get('survey_spec')
|
||||||
if new_spec is not None:
|
if new_spec is not None:
|
||||||
@@ -465,6 +501,9 @@ def main():
|
|||||||
associations={
|
associations={
|
||||||
'credentials': credentials_ids,
|
'credentials': credentials_ids,
|
||||||
'labels': labels_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,
|
on_create=on_change, on_update=on_change,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
jt1: "AWX-Collection-tests-tower_job_template-jt1-{{ test_id }}"
|
jt1: "AWX-Collection-tests-tower_job_template-jt1-{{ test_id }}"
|
||||||
jt2: "AWX-Collection-tests-tower_job_template-jt2-{{ test_id }}"
|
jt2: "AWX-Collection-tests-tower_job_template-jt2-{{ test_id }}"
|
||||||
lab1: "AWX-Collection-tests-tower_job_template-lab1-{{ 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
|
- name: Create a Demo Project
|
||||||
tower_project:
|
tower_project:
|
||||||
@@ -46,6 +47,22 @@
|
|||||||
name: "{{ lab1 }}"
|
name: "{{ lab1 }}"
|
||||||
organization: Default
|
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
|
- name: Create Job Template 1
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "{{ jt1 }}"
|
name: "{{ jt1 }}"
|
||||||
@@ -240,6 +257,37 @@
|
|||||||
that:
|
that:
|
||||||
- "result is changed"
|
- "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
|
- name: Delete Job Template 2
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: "{{ jt2 }}"
|
name: "{{ jt2 }}"
|
||||||
@@ -286,3 +334,9 @@
|
|||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
# You can't delete a label directly so no cleanup needed
|
# You can't delete a label directly so no cleanup needed
|
||||||
|
|
||||||
|
- name: Delete email notification
|
||||||
|
tower_notification:
|
||||||
|
name: "{{ email_not }}"
|
||||||
|
organization: Default
|
||||||
|
state: absent
|
||||||
|
|||||||
Reference in New Issue
Block a user