mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Updating tower_job_template.py (#38821)
* Updating tower_job_template.py * tower_job_template: Update parameter version_added to 2.7 * Ensure that unset credentials aren't passed Passing empty strings for unset credentials causes ValueErrors as the API expects an integer. Don't pass unset credentials
This commit is contained in:
parent
fc2c8a4ec8
commit
fb61680ccd
2 changed files with 117 additions and 46 deletions
|
@ -25,36 +25,35 @@ description:
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name to use for the job_template.
|
- Name to use for the job template.
|
||||||
required: True
|
required: True
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- Description to use for the job template.
|
- Description to use for the job template.
|
||||||
job_type:
|
job_type:
|
||||||
description:
|
description:
|
||||||
- The job_type to use for the job template.
|
- The job type to use for the job template.
|
||||||
required: True
|
required: True
|
||||||
choices: ["run", "check", "scan"]
|
choices: ["run", "check", "scan"]
|
||||||
inventory:
|
inventory:
|
||||||
description:
|
description:
|
||||||
- Inventory to use for the job template.
|
- Name of the inventory to use for the job template.
|
||||||
project:
|
project:
|
||||||
description:
|
description:
|
||||||
- Project to use for the job template.
|
- Name of the project to use for the job template.
|
||||||
required: True
|
required: True
|
||||||
playbook:
|
playbook:
|
||||||
description:
|
description:
|
||||||
- Playbook to use for the job template.
|
- Path to the playbook to use for the job template within the project provided.
|
||||||
required: True
|
required: True
|
||||||
machine_credential:
|
credential:
|
||||||
description:
|
description:
|
||||||
- Machine_credential to use for the job template.
|
- Name of the credential to use for the job template.
|
||||||
cloud_credential:
|
version_added: 2.7
|
||||||
|
vault_credential:
|
||||||
description:
|
description:
|
||||||
- Cloud_credential to use for the job template.
|
- Name of the vault credential to use for the job template.
|
||||||
network_credential:
|
version_added: 2.7
|
||||||
description:
|
|
||||||
- The network_credential to use for the job template.
|
|
||||||
forks:
|
forks:
|
||||||
description:
|
description:
|
||||||
- The number of parallel or simultaneous processes to use while executing the playbook.
|
- The number of parallel or simultaneous processes to use while executing the playbook.
|
||||||
|
@ -63,23 +62,52 @@ options:
|
||||||
- A host pattern to further constrain the list of hosts managed or affected by the playbook
|
- A host pattern to further constrain the list of hosts managed or affected by the playbook
|
||||||
verbosity:
|
verbosity:
|
||||||
description:
|
description:
|
||||||
- Control the output level Ansible produces as the playbook runs.
|
- Control the output level Ansible produces as the playbook runs. 0 - Normal, 1 - Verbose, 2 - More Verbose, 3 - Debug, 4 - Connection Debug.
|
||||||
choices: ["verbose", "debug"]
|
choices: [0, 1, 2, 3, 4]
|
||||||
job_tags:
|
default: 0
|
||||||
description:
|
|
||||||
- The job_tags to use for the job template.
|
|
||||||
skip_tags:
|
|
||||||
description:
|
|
||||||
- The skip_tags to use for the job template.
|
|
||||||
host_config_key:
|
|
||||||
description:
|
|
||||||
- Allow provisioning callbacks using this host config key.
|
|
||||||
extra_vars_path:
|
extra_vars_path:
|
||||||
description:
|
description:
|
||||||
- Path to the C(extra_vars) YAML file.
|
- Path to the C(extra_vars) YAML file.
|
||||||
|
job_tags:
|
||||||
|
description:
|
||||||
|
- Comma separated list of the tags to use for the job template.
|
||||||
|
force_handlers_enabled:
|
||||||
|
description:
|
||||||
|
- Enable forcing playbook handlers to run even if a task fails.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
|
skip_tags:
|
||||||
|
description:
|
||||||
|
- Comma separated list of the tags to skip for the job template.
|
||||||
|
start_at_task:
|
||||||
|
description:
|
||||||
|
- Start the playbook at the task matching this name.
|
||||||
|
version_added: 2.7
|
||||||
|
fact_caching_enabled:
|
||||||
|
description:
|
||||||
|
- Enable use of fact caching for the job template.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
|
host_config_key:
|
||||||
|
description:
|
||||||
|
- Allow provisioning callbacks using this host config key.
|
||||||
|
ask_diff_mode:
|
||||||
|
description:
|
||||||
|
- Prompt user to enable diff mode (show changes) to files when supported by modules.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
ask_extra_vars:
|
ask_extra_vars:
|
||||||
description:
|
description:
|
||||||
- Prompt user for C(extra_vars) on launch.
|
- Prompt user for (extra_vars) on launch.
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
|
ask_limit:
|
||||||
|
description:
|
||||||
|
- Prompt user for a limit on launch.
|
||||||
|
version_added: 2.7
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
ask_tags:
|
ask_tags:
|
||||||
|
@ -87,11 +115,23 @@ options:
|
||||||
- Prompt user for job tags on launch.
|
- Prompt user for job tags on launch.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
|
ask_skip_tags:
|
||||||
|
description:
|
||||||
|
- Prompt user for job tags to skip on launch.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
ask_job_type:
|
ask_job_type:
|
||||||
description:
|
description:
|
||||||
- Prompt user for job type on launch.
|
- Prompt user for job type on launch.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
|
ask_verbosity:
|
||||||
|
description:
|
||||||
|
- Prompt user to choose a verbosity level on launch.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
ask_inventory:
|
ask_inventory:
|
||||||
description:
|
description:
|
||||||
- Propmt user for inventory on launch.
|
- Propmt user for inventory on launch.
|
||||||
|
@ -102,11 +142,23 @@ options:
|
||||||
- Prompt user for credential on launch.
|
- Prompt user for credential on launch.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
|
survey_enabled:
|
||||||
|
description:
|
||||||
|
- Enable a survey on the job template.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
become_enabled:
|
become_enabled:
|
||||||
description:
|
description:
|
||||||
- Activate privilege escalation.
|
- Activate privilege escalation.
|
||||||
type: bool
|
type: bool
|
||||||
default: 'no'
|
default: 'no'
|
||||||
|
concurrent_jobs_enabled:
|
||||||
|
description:
|
||||||
|
- Allow simultaneous runs of the job template.
|
||||||
|
version_added: 2.7
|
||||||
|
type: bool
|
||||||
|
default: 'no'
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- Desired state of the resource.
|
- Desired state of the resource.
|
||||||
|
@ -119,13 +171,13 @@ extends_documentation_fragment: tower
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
- name: Create tower Ping job template
|
- name: Create tower Ping job template
|
||||||
tower_job_template:
|
tower_job_template:
|
||||||
name: Ping
|
name: "Ping"
|
||||||
job_type: run
|
job_type: "run"
|
||||||
inventory: Local
|
inventory: "Local"
|
||||||
project: Demo
|
project: "Demo"
|
||||||
playbook: ping.yml
|
playbook: "ping.yml"
|
||||||
machine_credential: Local
|
credential: "Local"
|
||||||
state: present
|
state: "present"
|
||||||
tower_config_file: "~/tower_cli.cfg"
|
tower_config_file: "~/tower_cli.cfg"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -147,11 +199,19 @@ def update_fields(p):
|
||||||
'''
|
'''
|
||||||
params = p.copy()
|
params = p.copy()
|
||||||
field_map = {
|
field_map = {
|
||||||
|
'fact_caching_enabled': 'use_fact_cache',
|
||||||
|
'ask_diff_mode': 'ask_diff_mode_on_launch',
|
||||||
'ask_extra_vars': 'ask_variables_on_launch',
|
'ask_extra_vars': 'ask_variables_on_launch',
|
||||||
'ask_limit': 'ask_limit_on_launch',
|
'ask_limit': 'ask_limit_on_launch',
|
||||||
'ask_tags': 'ask_tags_on_launch',
|
'ask_tags': 'ask_tags_on_launch',
|
||||||
|
'ask_skip_tags': 'ask_skip_tags_on_launch',
|
||||||
|
'ask_verbosity': 'ask_verbosity_on_launch',
|
||||||
|
'ask_inventory': 'ask_inventory_on_launch',
|
||||||
|
'ask_credential': 'ask_credential_on_launch',
|
||||||
'ask_job_type': 'ask_job_type_on_launch',
|
'ask_job_type': 'ask_job_type_on_launch',
|
||||||
'machine_credential': 'credential',
|
'diff_mode_enabled': 'diff_mode',
|
||||||
|
'concurrent_jobs_enabled': 'allow_simultaneous',
|
||||||
|
'force_handlers_enabled': 'force_handlers',
|
||||||
}
|
}
|
||||||
|
|
||||||
params_update = {}
|
params_update = {}
|
||||||
|
@ -172,9 +232,8 @@ def update_resources(module, p):
|
||||||
identity_map = {
|
identity_map = {
|
||||||
'project': 'name',
|
'project': 'name',
|
||||||
'inventory': 'name',
|
'inventory': 'name',
|
||||||
'machine_credential': 'name',
|
'credential': 'name',
|
||||||
'network_credential': 'name',
|
'vault_credential': 'name',
|
||||||
'cloud_credential': 'name',
|
|
||||||
}
|
}
|
||||||
for k, v in identity_map.items():
|
for k, v in identity_map.items():
|
||||||
try:
|
try:
|
||||||
|
@ -182,6 +241,9 @@ def update_resources(module, p):
|
||||||
key = 'credential' if '_credential' in k else k
|
key = 'credential' if '_credential' in k else k
|
||||||
result = tower_cli.get_resource(key).get(**{v: params[k]})
|
result = tower_cli.get_resource(key).get(**{v: params[k]})
|
||||||
params[k] = result['id']
|
params[k] = result['id']
|
||||||
|
elif k in params:
|
||||||
|
# unset empty parameters to avoid ValueError: invalid literal for int() with base 10: ''
|
||||||
|
del(params[k])
|
||||||
except (exc.NotFound) as excinfo:
|
except (exc.NotFound) as excinfo:
|
||||||
module.fail_json(msg='Failed to update job template: {0}'.format(excinfo), changed=False)
|
module.fail_json(msg='Failed to update job template: {0}'.format(excinfo), changed=False)
|
||||||
return params
|
return params
|
||||||
|
@ -191,28 +253,37 @@ def main():
|
||||||
argument_spec = tower_argument_spec()
|
argument_spec = tower_argument_spec()
|
||||||
argument_spec.update(dict(
|
argument_spec.update(dict(
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
description=dict(),
|
description=dict(default=''),
|
||||||
job_type=dict(choices=['run', 'check', 'scan'], required=True),
|
job_type=dict(choices=['run', 'check', 'scan'], required=True),
|
||||||
inventory=dict(),
|
inventory=dict(default=''),
|
||||||
project=dict(required=True),
|
project=dict(required=True),
|
||||||
playbook=dict(required=True),
|
playbook=dict(required=True),
|
||||||
machine_credential=dict(),
|
credential=dict(default=''),
|
||||||
cloud_credential=dict(),
|
vault_credential=dict(default=''),
|
||||||
network_credential=dict(),
|
|
||||||
forks=dict(type='int'),
|
forks=dict(type='int'),
|
||||||
limit=dict(),
|
limit=dict(default=''),
|
||||||
verbosity=dict(choices=['verbose', 'debug']),
|
verbosity=dict(type='int', choices=[0, 1, 2, 3, 4], default=0),
|
||||||
job_tags=dict(),
|
|
||||||
skip_tags=dict(),
|
|
||||||
host_config_key=dict(),
|
|
||||||
extra_vars_path=dict(type='path', required=False),
|
extra_vars_path=dict(type='path', required=False),
|
||||||
|
job_tags=dict(default=''),
|
||||||
|
force_handlers_enabled=dict(type='bool', default=False),
|
||||||
|
skip_tags=dict(default=''),
|
||||||
|
start_at_task=dict(default=''),
|
||||||
|
timeout=dict(type='int', default=0),
|
||||||
|
fact_caching_enabled=dict(type='bool', default=False),
|
||||||
|
host_config_key=dict(default=''),
|
||||||
|
ask_diff_mode=dict(type='bool', default=False),
|
||||||
ask_extra_vars=dict(type='bool', default=False),
|
ask_extra_vars=dict(type='bool', default=False),
|
||||||
ask_limit=dict(type='bool', default=False),
|
ask_limit=dict(type='bool', default=False),
|
||||||
ask_tags=dict(type='bool', default=False),
|
ask_tags=dict(type='bool', default=False),
|
||||||
|
ask_skip_tags=dict(type='bool', default=False),
|
||||||
ask_job_type=dict(type='bool', default=False),
|
ask_job_type=dict(type='bool', default=False),
|
||||||
|
ask_verbosity=dict(type='bool', default=False),
|
||||||
ask_inventory=dict(type='bool', default=False),
|
ask_inventory=dict(type='bool', default=False),
|
||||||
ask_credential=dict(type='bool', default=False),
|
ask_credential=dict(type='bool', default=False),
|
||||||
|
survey_enabled=dict(type='bool', default=False),
|
||||||
become_enabled=dict(type='bool', default=False),
|
become_enabled=dict(type='bool', default=False),
|
||||||
|
diff_mode_enabled=dict(type='bool', default=False),
|
||||||
|
concurrent_jobs_enabled=dict(type='bool', default=False),
|
||||||
state=dict(choices=['present', 'absent'], default='present'),
|
state=dict(choices=['present', 'absent'], default='present'),
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
project: Job Template Test Project
|
project: Job Template Test Project
|
||||||
inventory: Demo Inventory
|
inventory: Demo Inventory
|
||||||
playbook: hello_world.yml
|
playbook: hello_world.yml
|
||||||
machine_credential: Demo Credential
|
credential: Demo Credential
|
||||||
job_type: run
|
job_type: run
|
||||||
state: present
|
state: present
|
||||||
register: result
|
register: result
|
||||||
|
|
Loading…
Add table
Reference in a new issue