mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 06:51:10 +03:00
Merge pull request #5562 from beeankha/job_launch_extra_vars_example
Add extra_vars Example to Job Launch Module Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
commit
b74f7f6c26
@ -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.
|
||||
- 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.
|
||||
|
||||
## Running
|
||||
|
||||
|
@ -43,8 +43,10 @@ options:
|
||||
type: str
|
||||
extra_vars:
|
||||
description:
|
||||
- Extra_vars to use for the job_template. Prepend C(@) if a file.
|
||||
type: list
|
||||
- extra_vars to use for the Job Template. Prepend C(@) if a file.
|
||||
- ask_extra_vars needs to be set to True via tower_job_template module
|
||||
when creating the Job Template.
|
||||
type: dict
|
||||
limit:
|
||||
description:
|
||||
- Limit to use for the I(job_template).
|
||||
@ -68,6 +70,15 @@ EXAMPLES = '''
|
||||
job_id: "{{ job.id }}"
|
||||
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
|
||||
- name: Launch a job with inventory and credential
|
||||
tower_job_launch:
|
||||
@ -94,6 +105,7 @@ status:
|
||||
sample: pending
|
||||
'''
|
||||
|
||||
import json
|
||||
|
||||
from ..module_utils.ansible_tower import TowerModule, tower_auth_config, tower_check_mode
|
||||
|
||||
@ -106,6 +118,19 @@ except ImportError:
|
||||
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():
|
||||
argument_spec = dict(
|
||||
job_template=dict(required=True, type='str'),
|
||||
@ -114,11 +139,11 @@ def main():
|
||||
credential=dict(type='str', default=None),
|
||||
limit=dict(),
|
||||
tags=dict(type='list'),
|
||||
extra_vars=dict(type='list'),
|
||||
extra_vars=dict(type='dict', required=False),
|
||||
)
|
||||
|
||||
module = TowerModule(
|
||||
argument_spec,
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
@ -134,6 +159,8 @@ def main():
|
||||
params['tags'] = ','.join(tags)
|
||||
job = tower_cli.get_resource('job')
|
||||
|
||||
params = update_fields(module, params)
|
||||
|
||||
lookup_fields = ('job_template', 'inventory', 'credential')
|
||||
for field in lookup_fields:
|
||||
try:
|
||||
|
@ -42,17 +42,23 @@ def test_job_launch_with_prompting(run_module, admin_user, project, inventory, m
|
||||
name='foo',
|
||||
project=project,
|
||||
playbook='helloworld.yml',
|
||||
ask_variables_on_launch=True,
|
||||
ask_inventory_on_launch=True,
|
||||
ask_credential_on_launch=True
|
||||
)
|
||||
result = run_module('tower_job_launch', dict(
|
||||
job_template='foo',
|
||||
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)
|
||||
assert result.pop('changed', None), result
|
||||
|
||||
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 [cred.id for cred in job.credentials.all()] == [machine_credential.id]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user