mirror of
https://github.com/ansible/awx.git
synced 2026-02-20 20:50:06 -03:30
clean up and tests added
This commit is contained in:
@@ -93,6 +93,24 @@ options:
|
||||
- Can be a job template, project, inventory source, etc.
|
||||
- Omit if creating an approval node (not yet implemented).
|
||||
type: str
|
||||
approval_node:
|
||||
description:
|
||||
- A dictionary of Name, description, and timeout values for the approval node.
|
||||
type: dict
|
||||
suboptions:
|
||||
name:
|
||||
description:
|
||||
- Name of this workflow approval template.
|
||||
type: str
|
||||
required: True
|
||||
description:
|
||||
description:
|
||||
- Optional description of this workflow approval template.
|
||||
type: str
|
||||
timeout:
|
||||
description:
|
||||
- The amount of time (in seconds) before the approval node expires and fails.
|
||||
type: int
|
||||
all_parents_must_converge:
|
||||
description:
|
||||
- If enabled then the node will only run if all of the parent nodes have met the criteria to reach this node
|
||||
@@ -166,10 +184,6 @@ def main():
|
||||
identifier=dict(required=True),
|
||||
workflow_job_template=dict(required=True, aliases=['workflow']),
|
||||
organization=dict(),
|
||||
approval_node=dict(type='bool'),
|
||||
name=dict(),
|
||||
description=dict(),
|
||||
timeout=dict(type='int'),
|
||||
extra_data=dict(type='dict'),
|
||||
inventory=dict(),
|
||||
scm_branch=dict(),
|
||||
@@ -180,11 +194,11 @@ def main():
|
||||
diff_mode=dict(type='bool'),
|
||||
verbosity=dict(choices=['0', '1', '2', '3', '4', '5']),
|
||||
unified_job_template=dict(),
|
||||
approval_node=dict(type='dict'),
|
||||
all_parents_must_converge=dict(type='bool'),
|
||||
success_nodes=dict(type='list', elements='str'),
|
||||
always_nodes=dict(type='list', elements='str'),
|
||||
failure_nodes=dict(type='list', elements='str'),
|
||||
approval_nodes=dict(type='list', elements='str'),
|
||||
credentials=dict(type='list', elements='str'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
)
|
||||
@@ -196,9 +210,6 @@ def main():
|
||||
identifier = module.params.get('identifier')
|
||||
state = module.params.get('state')
|
||||
approval_node = module.params.get('approval_node')
|
||||
name = module.params.get('name')
|
||||
description = module.params.get('description')
|
||||
timeout = module.params.get('timeout')
|
||||
new_fields = {}
|
||||
search_fields = {'identifier': identifier}
|
||||
|
||||
@@ -245,7 +256,7 @@ def main():
|
||||
new_fields[field_name] = field_val
|
||||
|
||||
association_fields = {}
|
||||
for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'approval_nodes', 'credentials'):
|
||||
for association in ('always_nodes', 'success_nodes', 'failure_nodes', 'credentials'):
|
||||
name_list = module.params.get(association)
|
||||
if name_list is None:
|
||||
continue
|
||||
@@ -275,23 +286,31 @@ def main():
|
||||
endpoint='workflow_job_template_nodes', item_type='workflow_job_template_node', on_continue=approval_node,
|
||||
associations=association_fields
|
||||
)
|
||||
|
||||
# Create approval node unified template or update existing
|
||||
if approval_node:
|
||||
# Set Approval Fields
|
||||
new_fields = {}
|
||||
if name is not None:
|
||||
new_fields['name'] = name
|
||||
if description is not None:
|
||||
new_fields['description'] = description
|
||||
if timeout is not None:
|
||||
new_fields['timeout'] = timeout
|
||||
# Find created approval node ID
|
||||
|
||||
# Extract Parameters
|
||||
if approval_node.get('name') is None:
|
||||
module.fail_json(msg="Approval node name is required to create approval node.")
|
||||
if approval_node.get('name') is not None:
|
||||
new_fields['name'] = approval_node['name']
|
||||
if approval_node.get('description') is not None:
|
||||
new_fields['description'] = approval_node['description']
|
||||
if approval_node.get('timeout') is not None:
|
||||
new_fields['timeout'] = approval_node['timeout']
|
||||
|
||||
# Find created workflow node ID
|
||||
search_fields = {'identifier': identifier}
|
||||
search_fields['workflow_job_template'] = workflow_job_template_id
|
||||
workflow_job_template_node = module.get_one('workflow_job_template_nodes', **{'data': search_fields})
|
||||
workflow_job_template_node_id = workflow_job_template_node['id']
|
||||
# Due to not able to lookup workflow_approval_templates, none existing item
|
||||
existing_item = {}
|
||||
# module.fail_json(msg="workflow_job_template_nodes/{0}/create_approval_template/".format(workflow_job_template_node_id))
|
||||
module.json_output['workflow_node_id'] = workflow_job_template_node_id
|
||||
# Due to not able to lookup workflow_approval_templates, find the existing item in another place
|
||||
if workflow_job_template_node['related'].get('unified_job_template') is not None:
|
||||
existing_item = module.get_endpoint(workflow_job_template_node['related']['unified_job_template'])['json']
|
||||
module.create_or_update_if_needed(
|
||||
existing_item, new_fields,
|
||||
endpoint='workflow_job_template_nodes/' + str(workflow_job_template_node_id) + '/create_approval_template/', item_type='workflow_job_template_approval_node', on_continue=approval_node,
|
||||
|
||||
Reference in New Issue
Block a user