related #8344 add support for wait of project_updates jobs, inventory_update, and workflow_job.

Signed-off-by: Donald Picard <donald.picard@sogeti.com>
This commit is contained in:
Donald Picard 2020-10-07 11:00:17 -04:00
parent 81a79c30cb
commit 8f66cfa2c0
2 changed files with 57 additions and 3 deletions

View File

@ -30,7 +30,7 @@ options:
interval:
description:
- The interval in sections, to request an update from Tower.
- For backwards compatability if unset this will be set to the average of min and max intervals
- For backwards compatibility if unset this will be set to the average of min and max intervals
required: False
default: 1
type: float
@ -48,6 +48,12 @@ options:
description:
- Maximum time in seconds to wait for a job to finish.
type: int
job_type:
description:
- Job type to wait for
choices: ['project_updates', 'jobs', 'inventory_updates', 'workflow_jobs']
default: 'jobs'
type: str
extends_documentation_fragment: awx.awx.auth
'''
@ -99,6 +105,7 @@ def main():
# Any additional arguments that are not fields of the item can be added here
argument_spec = dict(
job_id=dict(type='int', required=True),
job_type=dict(choices=['project_updates', 'jobs', 'inventory_updates', 'workflow_jobs'], default='jobs'),
timeout=dict(type='int'),
min_interval=dict(type='float'),
max_interval=dict(type='float'),
@ -110,6 +117,7 @@ def main():
# Extract our parameters
job_id = module.params.get('job_id')
job_type = module.params.get('job_type')
timeout = module.params.get('timeout')
min_interval = module.params.get('min_interval')
max_interval = module.params.get('max_interval')
@ -130,14 +138,14 @@ def main():
)
# Attempt to look up job based on the provided id
job = module.get_one('jobs', **{
job = module.get_one(job_type, **{
'data': {
'id': job_id,
}
})
if job is None:
module.fail_json(msg='Unable to wait on job {0}; that ID does not exist in Tower.'.format(job_id))
module.fail_json(msg='Unable to wait on ' + job_type.rstrip("s") + ' {0}; that ID does not exist in Tower.'.format(job_id))
# Invoke wait function
result = module.wait_on_url(

View File

@ -135,3 +135,49 @@
name: "{{ proj_name }}"
organization: Default
state: absent
# tower workflow wait test
- name: Generate a random string for test
set_fact:
test_id1: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id1 is not defined
- name: Generate names
set_fact:
wfjt_name2: "AWX-Collection-tests-tower_workflow_launch--wfjt1-{{ test_id1 }}"
- name: Create our workflow
tower_workflow_job_template:
name: "{{ wfjt_name2 }}"
state: present
- name: Add a node
tower_workflow_job_template_node:
workflow_job_template: "{{ wfjt_name2 }}"
unified_job_template: "Demo Job Template"
identifier: leaf
register: new_node
- name: Kick off a workflow
tower_workflow_launch:
workflow_template: "{{ wfjt_name2 }}"
ignore_errors: true
register: workflow
- name: Wait for the Workflow Job to finish
tower_job_wait:
job_id: "{{ workflow.job_info.id }}"
job_type: "workflow_jobs"
register: wait_workflow_results
# Make sure it worked and that we have some data in our results
- assert:
that:
- wait_workflow_results is successful
- "'elapsed' in wait_workflow_results"
- "'id' in wait_workflow_results"
- name: Clean up test workflow
tower_workflow_job_template:
name: "{{ wfjt_name2 }}"
state: absent