Modernize types of WFJT module

This commit is contained in:
AlanCoding
2020-03-05 11:05:46 -05:00
parent 208dbc1f92
commit e80843846e
3 changed files with 59 additions and 11 deletions

View File

@@ -35,15 +35,20 @@ have it function as a collection.
The following notes are changes that may require changes to playbooks: The following notes are changes that may require changes to playbooks:
- Specifying `inputs` or `injectors` as strings in the
`tower_credential_type` module is no longer supported. Provide them as dictionaries instead.
- When a project is created, it will wait for the update/sync to finish by default; this can be turned off with the `wait` parameter, if desired. - When a project is created, it will wait for the update/sync to finish by default; this can be turned off with the `wait` parameter, if desired.
- Creating a "scan" type job template is no longer supported. - Creating a "scan" type job template is no longer supported.
- `extra_vars` in the `tower_job_launch` module worked with a list previously, but is now configured to work solely in a `dict` format. - Type changes of variable fields
- When the `extra_vars` parameter is used with the `tower_job_launch` module, the Job Template launch will fail unless `add_extra_vars` or `survey_enabled` is explicitly set to `True` on the Job Template. - `extra_vars` in the `tower_job_launch` module worked with a list previously, but is now configured to work solely in a `dict` format.
- `extra_vars` in the `tower_workflow_job_template` module worked with a string previously but now expects a dict.
- When the `extra_vars` parameter is used with the `tower_job_launch` module, the Job Template launch will fail unless `add_extra_vars` or `survey_enabled` is explicitly set to `True` on the Job Template.
- The `variables` parameter in the `tower_group`, `tower_host` and `tower_inventory` modules are now in `dict` format and no longer supports the use of the `C(@)` syntax (for an external `vars` file).
- Type changes of other types of fields
- Specifying `inputs` or `injectors` as strings in the
`tower_credential_type` module is no longer supported. Provide them as dictionaries instead.
- Specifying `schema` as in the `tower_workflow_job_template` module is no longer supported. Use a list of dicts instead.
- `tower_group` used to also service inventory sources, but this functionality has been removed from this module; use `tower_inventory_source` instead. - `tower_group` used to also service inventory sources, but this functionality has been removed from this module; use `tower_inventory_source` instead.
- 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.
- The `variables` parameter in the `tower_group`, `tower_host` and `tower_inventory` modules are now in `dict` format and no longer supports the use of the `C(@)` syntax (for an external `vars` file).
- 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.
## Running Unit Tests ## Running Unit Tests

View File

@@ -44,7 +44,7 @@ options:
extra_vars: extra_vars:
description: description:
- Extra variables used by Ansible in YAML or key=value format. - Extra variables used by Ansible in YAML or key=value format.
type: str type: dict
inventory: inventory:
description: description:
- Name of the inventory to use for the job template. - Name of the inventory to use for the job template.
@@ -65,7 +65,8 @@ options:
The schema is a JSON- or YAML-formatted string defining the The schema is a JSON- or YAML-formatted string defining the
hierarchy structure that connects the nodes. Refer to Tower hierarchy structure that connects the nodes. Refer to Tower
documentation for more information. documentation for more information.
type: str type: list
elements: dict
survey_enabled: survey_enabled:
description: description:
- Setting that variable will prompt the user for job type on the - Setting that variable will prompt the user for job type on the
@@ -111,6 +112,8 @@ from ..module_utils.ansible_tower import (
tower_check_mode tower_check_mode
) )
import json
try: try:
import tower_cli import tower_cli
import tower_cli.exceptions as exc import tower_cli.exceptions as exc
@@ -123,10 +126,10 @@ def main():
argument_spec = dict( argument_spec = dict(
name=dict(required=True), name=dict(required=True),
description=dict(required=False), description=dict(required=False),
extra_vars=dict(required=False), extra_vars=dict(type='dict', required=False),
organization=dict(required=False), organization=dict(required=False),
allow_simultaneous=dict(type='bool', required=False), allow_simultaneous=dict(type='bool', required=False),
schema=dict(required=False), schema=dict(type='list', elements='dict', required=False),
survey=dict(required=False), survey=dict(required=False),
survey_enabled=dict(type='bool', required=False), survey_enabled=dict(type='bool', required=False),
inventory=dict(required=False), inventory=dict(required=False),
@@ -187,18 +190,23 @@ def main():
if module.params.get('ask_inventory'): if module.params.get('ask_inventory'):
params['ask_inventory_on_launch'] = module.params.get('ask_inventory') params['ask_inventory_on_launch'] = module.params.get('ask_inventory')
for key in ('allow_simultaneous', 'extra_vars', 'inventory', for key in ('allow_simultaneous', 'inventory',
'survey_enabled', 'description'): 'survey_enabled', 'description'):
if module.params.get(key): if module.params.get(key):
params[key] = module.params.get(key) params[key] = module.params.get(key)
# Special treatment for tower-cli extra_vars
extra_vars = module.params.get('extra_vars')
if extra_vars:
params['extra_vars'] = [json.dumps(extra_vars)]
try: try:
if state == 'present': if state == 'present':
params['create_on_missing'] = True params['create_on_missing'] = True
result = wfjt_res.modify(**params) result = wfjt_res.modify(**params)
json_output['id'] = result['id'] json_output['id'] = result['id']
if schema: if schema:
wfjt_res.schema(result['id'], schema) wfjt_res.schema(result['id'], json.dumps(schema))
elif state == 'absent': elif state == 'absent':
params['fail_on_missing'] = False params['fail_on_missing'] = False
result = wfjt_res.delete(**params) result = wfjt_res.delete(**params)

View File

@@ -0,0 +1,35 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from awx.main.models import WorkflowJobTemplate
@pytest.mark.django_db
def test_create_workflow_job_template(run_module, admin_user, organization):
module_args = {
'name': 'foo-workflow',
'organization': organization.name,
'extra_vars': {'foo': 'bar', 'another-foo': {'barz': 'bar2'}},
'state': 'present'
}
result = run_module('tower_workflow_template', module_args, admin_user)
wfjt = WorkflowJobTemplate.objects.get(name='foo-workflow')
assert wfjt.extra_vars == '{"foo": "bar", "another-foo": {"barz": "bar2"}}'
result.pop('module_args', None)
assert result == {
"workflow_template": "foo-workflow", # TODO: remove after refactor
"state": "present",
"id": wfjt.id,
"changed": True,
"invocation": {
"module_args": module_args
}
}
assert wfjt.organization_id == organization.id