mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 02:17:37 -02:30
Add extra_vars example to Job Launch module, update extra_vars type to dict,
update unit test, add details to Collections release notes.
This commit is contained in:
@@ -20,6 +20,7 @@ The following notes are changes that may require changes to playbooks.
|
|||||||
`tower_credential_type` module is no longer supported. Provide as dictionaries instead.
|
`tower_credential_type` module is no longer supported. Provide 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.
|
||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ options:
|
|||||||
type: str
|
type: str
|
||||||
extra_vars:
|
extra_vars:
|
||||||
description:
|
description:
|
||||||
- Extra_vars to use for the job_template. Prepend C(@) if a file.
|
- extra_vars to use for the Job Template. Prepend C(@) if a file.
|
||||||
type: list
|
- ask_extra_vars needs to be set to True via tower_job_template module
|
||||||
|
when creating the Job Template.
|
||||||
|
type: dict
|
||||||
limit:
|
limit:
|
||||||
description:
|
description:
|
||||||
- Limit to use for the I(job_template).
|
- Limit to use for the I(job_template).
|
||||||
@@ -68,6 +70,15 @@ EXAMPLES = '''
|
|||||||
job_id: "{{ job.id }}"
|
job_id: "{{ job.id }}"
|
||||||
timeout: 120
|
timeout: 120
|
||||||
|
|
||||||
|
- name: Launch a job template with extra_vars on remote Tower instance
|
||||||
|
tower_job_launch:
|
||||||
|
job_template: "My Job Template"
|
||||||
|
extra_vars:
|
||||||
|
var1: "My First Variable"
|
||||||
|
var2: "My Second Variable"
|
||||||
|
var3: "My Third Variable"
|
||||||
|
job_type: run
|
||||||
|
|
||||||
# Launch job template with inventory and credential for prompt on launch
|
# Launch job template with inventory and credential for prompt on launch
|
||||||
- name: Launch a job with inventory and credential
|
- name: Launch a job with inventory and credential
|
||||||
tower_job_launch:
|
tower_job_launch:
|
||||||
@@ -94,6 +105,7 @@ status:
|
|||||||
sample: pending
|
sample: pending
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
||||||
|
|
||||||
@@ -106,6 +118,19 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def update_fields(module, p):
|
||||||
|
params = p.copy()
|
||||||
|
|
||||||
|
params_update = {}
|
||||||
|
extra_vars = params.get('extra_vars')
|
||||||
|
|
||||||
|
if extra_vars:
|
||||||
|
params_update['extra_vars'] = [json.dumps(extra_vars)]
|
||||||
|
|
||||||
|
params.update(params_update)
|
||||||
|
return params
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
job_template=dict(required=True, type='str'),
|
job_template=dict(required=True, type='str'),
|
||||||
@@ -114,11 +139,11 @@ def main():
|
|||||||
credential=dict(type='str', default=None),
|
credential=dict(type='str', default=None),
|
||||||
limit=dict(),
|
limit=dict(),
|
||||||
tags=dict(type='list'),
|
tags=dict(type='list'),
|
||||||
extra_vars=dict(type='list'),
|
extra_vars=dict(type='dict', required=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
module = TowerModule(
|
module = TowerModule(
|
||||||
argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -134,6 +159,8 @@ def main():
|
|||||||
params['tags'] = ','.join(tags)
|
params['tags'] = ','.join(tags)
|
||||||
job = tower_cli.get_resource('job')
|
job = tower_cli.get_resource('job')
|
||||||
|
|
||||||
|
params = update_fields(module, params)
|
||||||
|
|
||||||
lookup_fields = ('job_template', 'inventory', 'credential')
|
lookup_fields = ('job_template', 'inventory', 'credential')
|
||||||
for field in lookup_fields:
|
for field in lookup_fields:
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -42,17 +42,23 @@ def test_job_launch_with_prompting(run_module, admin_user, project, inventory, m
|
|||||||
name='foo',
|
name='foo',
|
||||||
project=project,
|
project=project,
|
||||||
playbook='helloworld.yml',
|
playbook='helloworld.yml',
|
||||||
|
ask_variables_on_launch=True,
|
||||||
ask_inventory_on_launch=True,
|
ask_inventory_on_launch=True,
|
||||||
ask_credential_on_launch=True
|
ask_credential_on_launch=True
|
||||||
)
|
)
|
||||||
result = run_module('tower_job_launch', dict(
|
result = run_module('tower_job_launch', dict(
|
||||||
job_template='foo',
|
job_template='foo',
|
||||||
inventory=inventory.name,
|
inventory=inventory.name,
|
||||||
credential=machine_credential.name
|
credential=machine_credential.name,
|
||||||
|
extra_vars={"var1": "My First Variable",
|
||||||
|
"var2": "My Second Variable",
|
||||||
|
"var3": "My Third Variable"
|
||||||
|
}
|
||||||
), admin_user)
|
), admin_user)
|
||||||
assert result.pop('changed', None), result
|
assert result.pop('changed', None), result
|
||||||
|
|
||||||
job = Job.objects.get(id=result['id'])
|
job = Job.objects.get(id=result['id'])
|
||||||
|
assert job.extra_vars == '{"var1": "My First Variable", "var2": "My Second Variable", "var3": "My Third Variable"}'
|
||||||
assert job.inventory == inventory
|
assert job.inventory == inventory
|
||||||
assert [cred.id for cred in job.credentials.all()] == [machine_credential.id]
|
assert [cred.id for cred in job.credentials.all()] == [machine_credential.id]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user