mirror of
https://github.com/ansible/awx.git
synced 2026-03-04 10:11:05 -03:30
Merge pull request #5450 from beeankha/tower_job_template_extra_vars
Add extra_vars Parameter to tower_job_template.py Module Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -85,8 +85,14 @@ options:
|
|||||||
choices: [0, 1, 2, 3, 4]
|
choices: [0, 1, 2, 3, 4]
|
||||||
default: 0
|
default: 0
|
||||||
type: int
|
type: int
|
||||||
|
extra_vars:
|
||||||
|
description:
|
||||||
|
- Specify C(extra_vars) for the template.
|
||||||
|
type: dict
|
||||||
|
version_added: 3.7
|
||||||
extra_vars_path:
|
extra_vars_path:
|
||||||
description:
|
description:
|
||||||
|
- This parameter has been deprecated, please use 'extra_vars' instead.
|
||||||
- Path to the C(extra_vars) YAML file.
|
- Path to the C(extra_vars) YAML file.
|
||||||
type: path
|
type: path
|
||||||
job_tags:
|
job_tags:
|
||||||
@@ -238,6 +244,8 @@ EXAMPLES = '''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
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
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import tower_cli
|
import tower_cli
|
||||||
@@ -248,7 +256,7 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_fields(p):
|
def update_fields(module, p):
|
||||||
'''This updates the module field names
|
'''This updates the module field names
|
||||||
to match the field names tower-cli expects to make
|
to match the field names tower-cli expects to make
|
||||||
calling of the modify/delete methods easier.
|
calling of the modify/delete methods easier.
|
||||||
@@ -275,9 +283,18 @@ def update_fields(p):
|
|||||||
v = params.pop(old_k)
|
v = params.pop(old_k)
|
||||||
params_update[new_k] = v
|
params_update[new_k] = v
|
||||||
|
|
||||||
extra_vars = params.get('extra_vars_path')
|
extra_vars = params.get('extra_vars')
|
||||||
if extra_vars is not None:
|
extra_vars_path = params.get('extra_vars_path')
|
||||||
params_update['extra_vars'] = ['@' + extra_vars]
|
|
||||||
|
if extra_vars:
|
||||||
|
params_update['extra_vars'] = [json.dumps(extra_vars)]
|
||||||
|
|
||||||
|
elif extra_vars_path is not None:
|
||||||
|
params_update['extra_vars'] = ['@' + extra_vars_path]
|
||||||
|
module.deprecate(
|
||||||
|
msg='extra_vars_path should not be used anymore. Use \'extra_vars: "{{ lookup(\'file\', \'/path/to/file\') | from_yaml }}"\' instead',
|
||||||
|
version="3.8"
|
||||||
|
)
|
||||||
|
|
||||||
params.update(params_update)
|
params.update(params_update)
|
||||||
return params
|
return params
|
||||||
@@ -320,6 +337,7 @@ def main():
|
|||||||
forks=dict(type='int'),
|
forks=dict(type='int'),
|
||||||
limit=dict(default=''),
|
limit=dict(default=''),
|
||||||
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
||||||
|
extra_vars=dict(type='dict', required=False),
|
||||||
extra_vars_path=dict(type='path', required=False),
|
extra_vars_path=dict(type='path', required=False),
|
||||||
job_tags=dict(default=''),
|
job_tags=dict(default=''),
|
||||||
force_handlers_enabled=dict(type='bool', default=False),
|
force_handlers_enabled=dict(type='bool', default=False),
|
||||||
@@ -350,7 +368,8 @@ def main():
|
|||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
mutually_exclusive=[
|
mutually_exclusive=[
|
||||||
('credential', 'credentials'),
|
('credential', 'credentials'),
|
||||||
('vault_credential', 'credentials')
|
('vault_credential', 'credentials'),
|
||||||
|
('extra_vars_path', 'extra_vars'),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -364,7 +383,7 @@ def main():
|
|||||||
jt = tower_cli.get_resource('job_template')
|
jt = tower_cli.get_resource('job_template')
|
||||||
|
|
||||||
params = update_resources(module, module.params)
|
params = update_resources(module, module.params)
|
||||||
params = update_fields(params)
|
params = update_fields(module, params)
|
||||||
params['create_on_missing'] = True
|
params['create_on_missing'] = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ def test_create_job_template(run_module, admin_user, project, inventory):
|
|||||||
module_args = {
|
module_args = {
|
||||||
'name': 'foo', 'playbook': 'helloworld.yml',
|
'name': 'foo', 'playbook': 'helloworld.yml',
|
||||||
'project': project.name, 'inventory': inventory.name,
|
'project': project.name, 'inventory': inventory.name,
|
||||||
|
'extra_vars': {'foo': 'bar'},
|
||||||
'job_type': 'run',
|
'job_type': 'run',
|
||||||
'state': 'present'
|
'state': 'present'
|
||||||
}
|
}
|
||||||
@@ -19,6 +20,7 @@ def test_create_job_template(run_module, admin_user, project, inventory):
|
|||||||
result = run_module('tower_job_template', module_args, admin_user)
|
result = run_module('tower_job_template', module_args, admin_user)
|
||||||
|
|
||||||
jt = JobTemplate.objects.get(name='foo')
|
jt = JobTemplate.objects.get(name='foo')
|
||||||
|
assert jt.extra_vars == '{"foo": "bar"}'
|
||||||
|
|
||||||
assert result == {
|
assert result == {
|
||||||
"job_template": "foo",
|
"job_template": "foo",
|
||||||
|
|||||||
Reference in New Issue
Block a user