-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor deprecated ansiblejob workflow to be a distinct code path (#143
) - This also fixes a critical bug in the conditionals for evaluating when to use the launch_workflow.yml tasks. - Prior to this change, AnsibleJob objects with a job_workflow_template name specified would run to completion without error, but the task to launch the workflow was skipped. - The job_runner role was restructured to be more readable. - Adds a deprecation warning when the old ansiblejob workflow CR option is used.
- Loading branch information
1 parent
c1ed3e9
commit 1cd9230
Showing
4 changed files
with
115 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
- name: Deprecation Warning | ||
debug: | ||
msg: "Using an AnsibleJob to run workflows is deprecated. Please use an AnsibleWorkflow instead." | ||
verbosity: 0 | ||
|
||
- name: Launch a job, if error update AnsibleJob status then end play | ||
block: | ||
- name: Launch job | ||
awx.awx.workflow_launch: | ||
name: "{{ lookup('env','TOWER_DEPRECATED_WORKFLOW_TEMPLATE_NAME') }}" | ||
extra_vars: "{{ ansible_job['resources'][0]['spec']['extra_vars'] | default(omit) }}" | ||
inventory: "{{ ansible_job['resources'][0]['spec']['inventory'] | default(omit) }}" | ||
tags: "{{ ansible_job['resources'][0]['spec']['job_tags'] | default(omit) }}" | ||
skip_tags: "{{ ansible_job['resources'][0]['spec']['skip_tags'] | default(omit) }}" | ||
register: job | ||
rescue: | ||
- name: Update status if job resulted in an error | ||
operator_sdk.util.k8s_status: | ||
api_version: tower.ansible.com/v1alpha1 | ||
kind: AnsibleJob | ||
name: "{{ lookup('env', 'ANSIBLEJOB_NAME') }}" | ||
namespace: "{{ lookup('env', 'ANSIBLEJOB_NAMESPACE') }}" | ||
status: | ||
ansibleJobResult: | ||
status: "error" | ||
error_message: "{{ job.msg }}" | ||
- name: End playbook run | ||
meta: end_play | ||
|
||
- name: Update AnsibleJob definition with Tower job id | ||
k8s: | ||
state: present | ||
definition: | ||
kind: AnsibleJob | ||
apiVersion: tower.ansible.com/v1alpha1 | ||
metadata: | ||
name: "{{ lookup('env', 'ANSIBLEJOB_NAME') }}" | ||
namespace: "{{ lookup('env', 'ANSIBLEJOB_NAMESPACE') }}" | ||
labels: | ||
tower_job_id: "{{ job.id }}" | ||
|
||
- name: Update AnsibleJob status with Tower job status and url | ||
operator_sdk.util.k8s_status: | ||
api_version: tower.ansible.com/v1alpha1 | ||
kind: AnsibleJob | ||
name: "{{ lookup('env', 'ANSIBLEJOB_NAME') }}" | ||
namespace: "{{ lookup('env', 'ANSIBLEJOB_NAMESPACE') }}" | ||
status: | ||
changed: "{{ job.changed }}" | ||
failed: "{{ job.failed }}" | ||
status: "{{ job.status }}" | ||
url: "{{ lookup('env', 'TOWER_HOST') + '/#/jobs/workflow/' + (job.id|string) }}" | ||
|
||
- name: Wait for the tower job, if error update AnsibleJob status then end play | ||
block: | ||
- name: Register Job result when complete | ||
awx.awx.job_wait: | ||
job_id: "{{ job.id }}" | ||
job_type: workflow_jobs | ||
register: job_result | ||
rescue: | ||
- name: Update status if job results in an error | ||
operator_sdk.util.k8s_status: | ||
api_version: tower.ansible.com/v1alpha1 | ||
kind: AnsibleJob | ||
name: "{{ lookup('env', 'ANSIBLEJOB_NAME') }}" | ||
namespace: "{{ lookup('env', 'ANSIBLEJOB_NAMESPACE') }}" | ||
status: | ||
ansibleJobResult: | ||
status: "error" | ||
error_message: "{{ job.msg }}" | ||
- name: End playbook run | ||
meta: end_play |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters