Merge pull request #6497 from john-westcott-iv/tower_notification_update

Initial conversion of tower_notification

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot]
2020-04-02 23:29:57 +00:00
committed by GitHub
4 changed files with 406 additions and 209 deletions

View File

@@ -51,6 +51,7 @@ The following notes are changes that may require changes to playbooks:
- Specified `tower_config` file used to handle `k=v` pairs on a single line; this is no longer supported. Please use a file formatted as `yaml`, `json` or `ini` only. - Specified `tower_config` file used to handle `k=v` pairs on a single line; this is no longer supported. Please use a file formatted as `yaml`, `json` or `ini` only.
- Some return values (e.g., `credential_type`) have been removed. Use of `id` is recommended. - Some return values (e.g., `credential_type`) have been removed. Use of `id` is recommended.
- `tower_job_template` no longer supports the deprecated `extra_vars_path` parameter, please use `extra_vars` with the lookup plugin to replace this functionality. - `tower_job_template` no longer supports the deprecated `extra_vars_path` parameter, please use `extra_vars` with the lookup plugin to replace this functionality.
- The `notification_configuration` parameter of `tower_notification` has changed from a string to a dict. Please use the `lookup` plugin to read an existing file into a dict.
## Running Unit Tests ## Running Unit Tests

View File

@@ -26,168 +26,182 @@ options:
name: name:
description: description:
- The name of the notification. - The name of the notification.
type: str
required: True required: True
new_name:
description:
- Setting this option will change the existing name (looked up via the name field.
type: str type: str
description: description:
description: description:
- The description of the notification. - The description of the notification.
required: False
type: str type: str
organization: organization:
description: description:
- The organization the notification belongs to. - The organization the notification belongs to.
required: False
type: str type: str
notification_type: notification_type:
description: description:
- The type of notification to be sent. - The type of notification to be sent.
required: True choices:
choices: ["email", "slack", "twilio", "pagerduty", "hipchat", "webhook", "irc"] - 'email'
- 'grafana'
- 'hipchat'
- 'irc'
- 'mattermost'
- 'pagerduty'
- 'rocketchat'
- 'slack'
- 'twilio'
- 'webhook'
type: str type: str
notification_configuration: notification_configuration:
description: description:
- The notification configuration file. Note providing this field would disable all notification-configuration-related fields. - The notification configuration file. Note providing this field would disable all notification-configuration-related fields.
required: False type: dict
type: str messages:
description:
- Optional custom messages for notification template.
type: dict
username: username:
description: description:
- The mail server username. Required if I(notification_type=email). - The mail server username.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
sender: sender:
description: description:
- The sender email address. Required if I(notification_type=email). - The sender email address.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
recipients: recipients:
description: description:
- The recipients email addresses. Required if I(notification_type=email). - The recipients email addresses.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: list type: list
elements: str elements: str
use_tls: use_tls:
description: description:
- The TLS trigger. Required if I(notification_type=email). - The TLS trigger.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: bool type: bool
host: host:
description: description:
- The mail server host. Required if I(notification_type=email). - The mail server host.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
use_ssl: use_ssl:
description: description:
- The SSL trigger. Required if I(notification_type=email) or if I(notification_type=irc). - The SSL trigger.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: bool type: bool
password: password:
description: description:
- The mail server password. Required if I(notification_type=email) or if I(notification_type=irc). - The mail server password.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
port: port:
description: description:
- The mail server port. Required if I(notification_type=email) or if I(notification_type=irc). - The mail server port.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: int type: int
channels: channels:
description: description:
- The destination Slack channels. Required if I(notification_type=slack). - The destination Slack channels.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: list type: list
elements: str elements: str
token: token:
description: description:
- The access token. Required if I(notification_type=slack), if I(notification_type=pagerduty) or if I(notification_type=hipchat). - The access token.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
account_token: account_token:
description: description:
- The Twillio account token. Required if I(notification_type=twillio). - The Twillio account token.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
from_number: from_number:
description: description:
- The source phone number. Required if I(notification_type=twillio). - The source phone number.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
to_numbers: to_numbers:
description: description:
- The destination phone numbers. Required if I(notification_type=twillio). - The destination phone numbers.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: list type: list
elements: str elements: str
account_sid: account_sid:
description: description:
- The Twillio account SID. Required if I(notification_type=twillio). - The Twillio account SID.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
subdomain: subdomain:
description: description:
- The PagerDuty subdomain. Required if I(notification_type=pagerduty). - The PagerDuty subdomain.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
service_key: service_key:
description: description:
- The PagerDuty service/integration API key. Required if I(notification_type=pagerduty). - The PagerDuty service/integration API key.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
client_name: client_name:
description: description:
- The PagerDuty client identifier. Required if I(notification_type=pagerduty). - The PagerDuty client identifier.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
message_from: message_from:
description: description:
- The label to be shown with the notification. Required if I(notification_type=hipchat). - The label to be shown with the notification.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
api_url: api_url:
description: description:
- The HipChat API URL. Required if I(notification_type=hipchat). - The HipChat API URL.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
color: color:
description: description:
- The notification color. Required if I(notification_type=hipchat). - The notification color.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
choices: ["yellow", "green", "red", "purple", "gray", "random"] choices: ["yellow", "green", "red", "purple", "gray", "random"]
type: str type: str
rooms: rooms:
description: description:
- HipChat rooms to send the notification to. Required if I(notification_type=hipchat). - HipChat rooms to send the notification to.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: list type: list
elements: str elements: str
notify: notify:
description: description:
- The notify channel trigger. Required if I(notification_type=hipchat). - The notify channel trigger.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: bool type: bool
url: url:
description: description:
- The target URL. Required if I(notification_type=webhook). - The target URL.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
headers: headers:
description: description:
- The HTTP headers as JSON string. Required if I(notification_type=webhook). - The HTTP headers as JSON string.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: dict type: dict
server: server:
description: description:
- The IRC server address. Required if I(notification_type=irc). - The IRC server address.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
nickname: nickname:
description: description:
- The IRC nickname. Required if I(notification_type=irc). - The IRC nickname.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: str type: str
targets: targets:
description: description:
- The destination channels or users. Required if I(notification_type=irc). - The destination channels or users.
required: False - This parameter has been deprecated, please use 'notification_configuration' instead.
type: list type: list
elements: str elements: str
state: state:
@@ -196,22 +210,32 @@ options:
default: "present" default: "present"
choices: ["present", "absent"] choices: ["present", "absent"]
type: str type: str
tower_oauthtoken:
requirements: description:
- ansible-tower-cli >= 3.0.2 - The Tower OAuth token to use.
version_added: "3.7"
type: str
extends_documentation_fragment: awx.awx.auth extends_documentation_fragment: awx.awx.auth
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: Add Slack notification - name: Add Slack notification with custom messages
tower_notification: tower_notification:
name: slack notification name: slack notification
organization: Default
notification_type: slack notification_type: slack
channels: notification_configuration:
- general channels:
token: cefda9e2be1f21d11cdd9452f5b7f97fda977f42 - general
token: cefda9e2be1f21d11cdd9452f5b7f97fda977f42
messages:
started:
message: "{{ '{{ job_friendly_name }}{{ job.id }} started' }}"
success:
message: "{{ '{{ job_friendly_name }} completed in {{ job.elapsed }} seconds' }}"
error:
message: "{{ '{{ job_friendly_name }} FAILED! Please look at {{ job.url }}' }}"
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
@@ -219,9 +243,10 @@ EXAMPLES = '''
tower_notification: tower_notification:
name: webhook notification name: webhook notification
notification_type: webhook notification_type: webhook
url: http://www.example.com/hook notification_configuration:
headers: url: http://www.example.com/hook
X-Custom-Header: value123 headers:
X-Custom-Header: value123
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
@@ -229,15 +254,16 @@ EXAMPLES = '''
tower_notification: tower_notification:
name: email notification name: email notification
notification_type: email notification_type: email
username: user notification_configuration:
password: s3cr3t username: user
sender: tower@example.com password: s3cr3t
recipients: sender: tower@example.com
- user1@example.com recipients:
host: smtp.example.com - user1@example.com
port: 25 host: smtp.example.com
use_tls: no port: 25
use_ssl: no use_tls: no
use_ssl: no
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
@@ -245,11 +271,12 @@ EXAMPLES = '''
tower_notification: tower_notification:
name: twilio notification name: twilio notification
notification_type: twilio notification_type: twilio
account_token: a_token notification_configuration:
account_sid: a_sid account_token: a_token
from_number: '+15551112222' account_sid: a_sid
to_numbers: from_number: '+15551112222'
- '+15553334444' to_numbers:
- '+15553334444'
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
@@ -257,10 +284,11 @@ EXAMPLES = '''
tower_notification: tower_notification:
name: pagerduty notification name: pagerduty notification
notification_type: pagerduty notification_type: pagerduty
token: a_token notification_configuration:
subdomain: sub token: a_token
client_name: client subdomain: sub
service_key: a_key client_name: client
service_key: a_key
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
@@ -268,13 +296,14 @@ EXAMPLES = '''
tower_notification: tower_notification:
name: hipchat notification name: hipchat notification
notification_type: hipchat notification_type: hipchat
token: a_token notification_configuration:
message_from: user1 token: a_token
api_url: https://hipchat.example.com message_from: user1
color: red api_url: https://hipchat.example.com
rooms: color: red
- room-A rooms:
notify: yes - room-A
notify: yes
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
@@ -282,20 +311,20 @@ EXAMPLES = '''
tower_notification: tower_notification:
name: irc notification name: irc notification
notification_type: irc notification_type: irc
nickname: tower notification_configuration:
password: s3cr3t nickname: tower
targets: password: s3cr3t
- user1 targets:
port: 8080 - user1
server: irc.example.com port: 8080
use_ssl: no server: irc.example.com
use_ssl: no
state: present state: present
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
- name: Delete notification - name: Delete notification
tower_notification: tower_notification:
name: old notification name: old notification
notification_type: email
state: absent state: absent
tower_config_file: "~/tower_cli.cfg" tower_config_file: "~/tower_cli.cfg"
''' '''
@@ -304,125 +333,123 @@ EXAMPLES = '''
RETURN = ''' # ''' RETURN = ''' # '''
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode from ..module_utils.tower_api import TowerModule
try: OLD_INPUT_NAMES = (
import tower_cli 'username', 'sender', 'recipients', 'use_tls',
import tower_cli.utils.exceptions as exc 'host', 'use_ssl', 'password', 'port',
'channels', 'token', 'account_token', 'from_number',
from tower_cli.conf import settings 'to_numbers', 'account_sid', 'subdomain', 'service_key',
except ImportError: 'client_name', 'message_from', 'api_url', 'color',
pass 'rooms', 'notify', 'url', 'headers', 'server',
'nickname', 'targets',
)
def main(): def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict( argument_spec = dict(
name=dict(required=True), name=dict(required=True),
description=dict(required=False), new_name=dict(),
organization=dict(required=False), description=dict(),
notification_type=dict(required=True, choices=['email', 'slack', 'twilio', 'pagerduty', 'hipchat', 'webhook', 'irc']), organization=dict(),
notification_configuration=dict(required=False), notification_type=dict(choices=[
username=dict(required=False), 'email', 'grafana', 'hipchat', 'irc', 'mattermost',
sender=dict(required=False), 'pagerduty', 'rocketchat', 'slack', 'twilio', 'webhook'
recipients=dict(required=False, type='list', elements='str'), ]),
use_tls=dict(required=False, type='bool'), notification_configuration=dict(type='dict'),
host=dict(required=False), messages=dict(type='dict'),
use_ssl=dict(required=False, type='bool'), username=dict(),
password=dict(required=False, no_log=True), sender=dict(),
port=dict(required=False, type='int'), recipients=dict(type='list', elements='str'),
channels=dict(required=False, type='list', elements='str'), use_tls=dict(type='bool'),
token=dict(required=False, no_log=True), host=dict(),
account_token=dict(required=False, no_log=True), use_ssl=dict(type='bool'),
from_number=dict(required=False), password=dict(no_log=True),
to_numbers=dict(required=False, type='list', elements='str'), port=dict(type='int'),
account_sid=dict(required=False), channels=dict(type='list', elements='str'),
subdomain=dict(required=False), token=dict(no_log=True),
service_key=dict(required=False, no_log=True), account_token=dict(no_log=True),
client_name=dict(required=False), from_number=dict(),
message_from=dict(required=False), to_numbers=dict(type='list', elements='str'),
api_url=dict(required=False), account_sid=dict(),
color=dict(required=False, choices=['yellow', 'green', 'red', 'purple', 'gray', 'random']), subdomain=dict(),
rooms=dict(required=False, type='list', elements='str'), service_key=dict(no_log=True),
notify=dict(required=False, type='bool'), client_name=dict(),
url=dict(required=False), message_from=dict(),
headers=dict(required=False, type='dict', default={}), api_url=dict(),
server=dict(required=False), color=dict(choices=['yellow', 'green', 'red', 'purple', 'gray', 'random']),
nickname=dict(required=False), rooms=dict(type='list', elements='str'),
targets=dict(required=False, type='list', elements='str'), notify=dict(type='bool'),
url=dict(),
headers=dict(type='dict'),
server=dict(),
nickname=dict(),
targets=dict(type='list', elements='str'),
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
) )
# Create a module for ourselves
module = TowerModule(argument_spec=argument_spec, supports_check_mode=True) module = TowerModule(argument_spec=argument_spec, supports_check_mode=True)
# Extract our parameters
name = module.params.get('name') name = module.params.get('name')
new_name = module.params.get("new_name")
description = module.params.get('description') description = module.params.get('description')
organization = module.params.get('organization') organization = module.params.get('organization')
notification_type = module.params.get('notification_type') notification_type = module.params.get('notification_type')
notification_configuration = module.params.get('notification_configuration') notification_configuration = module.params.get('notification_configuration')
username = module.params.get('username') messages = module.params.get('messages')
sender = module.params.get('sender')
recipients = module.params.get('recipients')
use_tls = module.params.get('use_tls')
host = module.params.get('host')
use_ssl = module.params.get('use_ssl')
password = module.params.get('password')
port = module.params.get('port')
channels = module.params.get('channels')
token = module.params.get('token')
account_token = module.params.get('account_token')
from_number = module.params.get('from_number')
to_numbers = module.params.get('to_numbers')
account_sid = module.params.get('account_sid')
subdomain = module.params.get('subdomain')
service_key = module.params.get('service_key')
client_name = module.params.get('client_name')
message_from = module.params.get('message_from')
api_url = module.params.get('api_url')
color = module.params.get('color')
rooms = module.params.get('rooms')
notify = module.params.get('notify')
url = module.params.get('url')
headers = module.params.get('headers')
server = module.params.get('server')
nickname = module.params.get('nickname')
targets = module.params.get('targets')
state = module.params.get('state') state = module.params.get('state')
json_output = {'notification': name, 'state': state} # Attempt to look up the related items the user specified (these will fail the module if not found)
organization_id = None
if organization:
organization_id = module.resolve_name_to_id('organizations', organization)
tower_auth = tower_auth_config(module) # Attempt to look up an existing item based on the provided data
with settings.runtime_values(**tower_auth): existing_item = module.get_one('notification_templates', **{
tower_check_mode(module) 'data': {
notification_template = tower_cli.get_resource('notification_template') 'name': name,
'organization': organization_id,
}
})
try: # Create notification_configuration from legacy inputs
org_res = tower_cli.get_resource('organization') final_notification_configuration = {}
org = org_res.get(name=organization) for legacy_input in OLD_INPUT_NAMES:
if module.params.get(legacy_input) is not None:
module.deprecate(msg='{0} parameter has been deprecated, please use notification_configuration instead.'.format(legacy_input), version="3.6")
final_notification_configuration[legacy_input] = module.params.get(legacy_input)
# Give anything in notification_configuration prescedence over the individual inputs
if notification_configuration is not None:
final_notification_configuration.update(notification_configuration)
if state == 'present': # Create the data that gets sent for create and update
result = notification_template.modify(name=name, description=description, organization=org['id'], new_fields = {}
notification_type=notification_type, if final_notification_configuration:
notification_configuration=notification_configuration, new_fields['notification_configuration'] = final_notification_configuration
username=username, sender=sender, recipients=recipients, new_fields['name'] = new_name if new_name else name
use_tls=use_tls, host=host, use_ssl=use_ssl, password=password, if description is not None:
port=port, channels=channels, token=token, new_fields['description'] = description
account_token=account_token, from_number=from_number, if organization is not None:
to_numbers=to_numbers, account_sid=account_sid, new_fields['organization'] = organization_id
subdomain=subdomain, service_key=service_key, if notification_type is not None:
client_name=client_name, message_from=message_from, new_fields['notification_type'] = notification_type
api_url=api_url, color=color, rooms=rooms, notify=notify, if messages is not None:
url=url, headers=headers, server=server, nickname=nickname, new_fields['messages'] = messages
targets=targets, create_on_missing=True)
json_output['id'] = result['id']
elif state == 'absent':
result = notification_template.delete(name=name)
except (exc.NotFound) as excinfo:
module.fail_json(msg='Failed to update notification template, organization not found: {0}'.format(excinfo), changed=False)
except (exc.ConnectionError, exc.BadRequest, exc.AuthError) as excinfo:
module.fail_json(msg='Failed to update notification template: {0}'.format(excinfo), changed=False)
json_output['changed'] = result['changed'] if state == 'absent':
module.exit_json(**json_output) # 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)
elif state == 'present':
# 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, new_fields,
endpoint='notification_templates', item_type='notification_template',
associations={
}
)
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -0,0 +1,112 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from awx.main.models import NotificationTemplate
def compare_with_encrypted(model_config, param_config):
'''Given a model_config from the database, assure that this is consistent
with the config given in the notification_configuration parameter
this requires handling of password fields
'''
for key, model_val in model_config.items():
param_val = param_config.get(key, 'missing')
if isinstance(model_val, str) and (model_val.startswith('$encrypted$') or param_val.startswith('$encrypted$')):
assert model_val.startswith('$encrypted$') # must be saved as encrypted
assert len(model_val) > len('$encrypted$')
else:
assert model_val == param_val, 'Config key {0} did not match, (model: {1}, input: {2})'.format(
key, model_val, param_val
)
@pytest.mark.django_db
def test_create_modify_notification_template(run_module, admin_user, organization):
nt_config = {
'username': 'user',
'password': 'password',
'sender': 'foo@invalid.com',
'recipients': ['foo2@invalid.com'],
'host': 'smtp.example.com',
'port': 25,
'use_tls': False, 'use_ssl': False,
'timeout': 4
}
result = run_module('tower_notification', dict(
name='foo-notification-template',
organization=organization.name,
notification_type='email',
notification_configuration=nt_config,
), admin_user)
assert not result.get('failed', False), result.get('msg', result)
assert result.pop('changed', None), result
nt = NotificationTemplate.objects.get(id=result['id'])
compare_with_encrypted(nt.notification_configuration, nt_config)
assert nt.organization == organization
# Test no-op, this is impossible if the notification_configuration is given
# because we cannot determine if password fields changed
result = run_module('tower_notification', dict(
name='foo-notification-template',
organization=organization.name,
notification_type='email',
), admin_user)
assert not result.get('failed', False), result.get('msg', result)
assert not result.pop('changed', None), result
# Test a change in the configuration
nt_config['timeout'] = 12
result = run_module('tower_notification', dict(
name='foo-notification-template',
organization=organization.name,
notification_type='email',
notification_configuration=nt_config,
), admin_user)
assert not result.get('failed', False), result.get('msg', result)
assert result.pop('changed', None), result
nt.refresh_from_db()
compare_with_encrypted(nt.notification_configuration, nt_config)
@pytest.mark.django_db
def test_invalid_notification_configuration(run_module, admin_user, organization):
result = run_module('tower_notification', dict(
name='foo-notification-template',
organization=organization.name,
notification_type='email',
notification_configuration={},
), admin_user)
assert result.get('failed', False), result.get('msg', result)
assert 'Missing required fields for Notification Configuration' in result['msg']
@pytest.mark.django_db
@pytest.mark.xfail(reason='Handling API validation changes w.r.t. changed status is an open item')
def test_deprecated_to_modern_no_op(run_module, admin_user, organization):
nt_config = {
'url': 'http://www.example.com/hook',
'headers': {
'X-Custom-Header': 'value123'
}
}
result = run_module('tower_notification', dict(
name='foo-notification-template',
organization=organization.name,
notification_type='webhook',
notification_configuration=nt_config,
), admin_user)
assert not result.get('failed', False), result.get('msg', result)
assert result.pop('changed', None), result
result = run_module('tower_notification', dict(
name='foo-notification-template',
organization=organization.name,
notification_type='webhook',
notification_configuration=nt_config,
), admin_user)
assert not result.get('failed', False), result.get('msg', result)
assert not result.pop('changed', None), result

View File

@@ -9,7 +9,64 @@
hipchat_not: "AWX-Collection-tests-tower_notification-hipchat-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" hipchat_not: "AWX-Collection-tests-tower_notification-hipchat-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
irc_not: "AWX-Collection-tests-tower_notification-irc-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}" irc_not: "AWX-Collection-tests-tower_notification-irc-not-{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
- name: Create Slack notification - name: Test deprecation warnings
tower_notification:
name: "{{ slack_not }}"
organization: Default
notification_type: slack
username: maw
sender: maw
recipients:
- everyone
use_tls: true
host: all
use_ssl: false
password: password
port: 12
channels:
- general
token: chunkecheese
account_token: asdf1234
from_number: "1 (888) 733-4281"
to_numbers:
- 867-5309
account_sid: vicious
subdomain: 'redhat.com'
service_key: skeleton
client_name: Bill
message_from: me
api_url: https://tower.example.com/api/v2
color: green
rooms:
- The Study
- Kitchen
- Ballroom
- Conservatory
- Billiard Room
- Library
- Hall
- Lounge
- Dining Room
- Cellar
notify: true
url: ansible.com
headers:
X-Custom-Header: value123
server: littimer.somewhere.com
nickname: chalk
targets:
- zombie
state: absent
register: result
ignore_errors: true
- assert:
that:
- "'deprecations' in result"
# The 27 can be count from the size of the OLD_INPUT_NAMES list in the module
- result['deprecations'] | length() == 27
- name: Create Slack notification with custom messages
tower_notification: tower_notification:
name: "{{ slack_not }}" name: "{{ slack_not }}"
organization: Default organization: Default
@@ -17,6 +74,13 @@
token: a_token token: a_token
channels: channels:
- general - general
messages:
started:
message: "{{ '{{' }} job_friendly_name {{' }}' }} {{ '{{' }} job.id {{' }}' }} started"
success:
message: "{{ '{{' }} job_friendly_name {{ '}}' }} completed in {{ '{{' }} job.elapsed {{ '}}' }} seconds"
error:
message: "{{ '{{' }} job_friendly_name {{ '}}' }} FAILED! Please look at {{ '{{' }} job.url {{ '}}' }}"
state: present state: present
register: result register: result
@@ -28,7 +92,6 @@
tower_notification: tower_notification:
name: "{{ slack_not }}" name: "{{ slack_not }}"
organization: Default organization: Default
notification_type: slack
state: absent state: absent
register: result register: result
@@ -55,7 +118,6 @@
tower_notification: tower_notification:
name: "{{ webhook_not }}" name: "{{ webhook_not }}"
organization: Default organization: Default
notification_type: webhook
state: absent state: absent
register: result register: result
@@ -88,7 +150,6 @@
tower_notification: tower_notification:
name: "{{ email_not }}" name: "{{ email_not }}"
organization: Default organization: Default
notification_type: email
state: absent state: absent
register: result register: result
@@ -117,7 +178,6 @@
tower_notification: tower_notification:
name: "{{ twillo_not }}" name: "{{ twillo_not }}"
organization: Default organization: Default
notification_type: twilio
state: absent state: absent
register: result register: result
@@ -145,7 +205,6 @@
tower_notification: tower_notification:
name: "{{ pd_not }}" name: "{{ pd_not }}"
organization: Default organization: Default
notification_type: pagerduty
state: absent state: absent
register: result register: result
@@ -176,7 +235,6 @@
tower_notification: tower_notification:
name: "{{ hipchat_not }}" name: "{{ hipchat_not }}"
organization: Default organization: Default
notification_type: hipchat
state: absent state: absent
register: result register: result
@@ -207,7 +265,6 @@
tower_notification: tower_notification:
name: "{{ irc_not }}" name: "{{ irc_not }}"
organization: Default organization: Default
notification_type: irc
state: absent state: absent
register: result register: result