diff --git a/awx_collection/README.md b/awx_collection/README.md index c9abe15542..7c6108a3c4 100644 --- a/awx_collection/README.md +++ b/awx_collection/README.md @@ -35,15 +35,20 @@ have it function as a collection. 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. - 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. - - 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. + - Type changes of variable fields + - `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. - 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. ## Running Unit Tests diff --git a/awx_collection/plugins/modules/tower_workflow_template.py b/awx_collection/plugins/modules/tower_workflow_template.py index e00ca48b6b..7a7d84052c 100644 --- a/awx_collection/plugins/modules/tower_workflow_template.py +++ b/awx_collection/plugins/modules/tower_workflow_template.py @@ -44,7 +44,7 @@ options: extra_vars: description: - Extra variables used by Ansible in YAML or key=value format. - type: str + type: dict inventory: description: - 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 hierarchy structure that connects the nodes. Refer to Tower documentation for more information. - type: str + type: list + elements: dict survey_enabled: description: - 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 ) +import json + try: import tower_cli import tower_cli.exceptions as exc @@ -123,10 +126,10 @@ def main(): argument_spec = dict( name=dict(required=True), description=dict(required=False), - extra_vars=dict(required=False), + extra_vars=dict(type='dict', required=False), organization=dict(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_enabled=dict(type='bool', required=False), inventory=dict(required=False), @@ -187,18 +190,23 @@ def main(): if 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'): if 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: if state == 'present': params['create_on_missing'] = True result = wfjt_res.modify(**params) json_output['id'] = result['id'] if schema: - wfjt_res.schema(result['id'], schema) + wfjt_res.schema(result['id'], json.dumps(schema)) elif state == 'absent': params['fail_on_missing'] = False result = wfjt_res.delete(**params) diff --git a/awx_collection/test/awx/test_workflow_template.py b/awx_collection/test/awx/test_workflow_template.py new file mode 100644 index 0000000000..47679ac21e --- /dev/null +++ b/awx_collection/test/awx/test_workflow_template.py @@ -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