Overview
A workflow’s purpose is to trigger other jobs in specific orders to achieve certain goals, such as tracking the full set of jobs that were part of a release process as a single unit. Each workflow has an associated tree-graph composed of multiple nodes.Workflow Components
Workflow Nodes contain one of the following template types:- Job templates
- Inventory updates
- Project updates
- Approval templates
- Workflow job templates (nested workflows)
Creating Workflows
Create Workflow Job Template
Like other job resources, workflow jobs are created from workflow job templates. The API exposes common fields similar to job templates:
- Labels
- Schedules
- Notification templates
- Extra variables
- Survey specifications
Add Workflow Nodes
Access workflow nodes via the Or directly under:
workflow_nodes related field. Create nodes under:Workflow Permissions
By default, organization administrators have full control over all workflow job templates under the same organization. They share these abilities with users who have the
workflow_admin_role.Node Configuration
Node Identifiers
Workflow nodes have anidentifier field that enables idempotent CRUD actions:
- Functions like the
namefield for other resources - If not provided, the server assigns a random UUID4 value
- Workflow job nodes spawned from a template node share the same
identifier - Enables tracking which job nodes correspond to which template nodes
Launch Configuration
Workflow job templates can contain launch configuration items:extra_vars
Extra variables with optional survey specifications
inventory
Override default inventory
limit
Limit hosts for execution
scm_branch
Specify source control branch
Prompt Precedence
When a workflow job template is launched:- Workflow job is created with user-provided values (if prompted)
- A workflow job node is created for each template node
- If both workflow job and node specify the same prompt, the workflow job takes precedence
- If the referenced job template doesn’t have the prompting field enabled (e.g.,
ask_inventory_on_launch), the prompt is ignored
Advanced Features
Nested Workflows
A workflow can be added as a node in another workflow:- The child workflow is the
unified_job_templatethat the node references - Parent workflow resumes when child workflow finishes
- Branching decisions based on child workflow status
Approval Nodes
Workflow approval nodes enable human decision points within workflows. Who Can Approve:- Superusers
- Workflow Admins
- Organization Admins
- Users explicitly assigned the “approver” role
- Superusers
- Org Admins of the connected organization
- Workflow Admins in the connected organization
- Users assigned as admins to the specific workflow
0 for no expiration.
Artifacts
Workflows support passing data between jobs using Ansible’sset_stats module.
Artifacts from parent nodes are available to child nodes. If both a parent and grandparent set the same artifact, the parent’s value overwrites the grandparent’s value.
Workflow Execution
Launch Process
Create Job Nodes
Workflow job template creates a workflow job, and all template nodes create job nodes
Execute Root Nodes
All root nodes (nodes with no incoming connections) populate with job resources and start running
Job Status Handling
Spawned job resources can end with the following statuses:- Success - Triggers success nodes
- Failure - Triggers failure nodes
- Error - Treated as failure
- Canceled - Treated as failure
Workflow Cancellation
When a workflow job is canceled:- All spawned job resources are canceled (if cancellation is allowed)
- Following paths stop executing
- Deletion of spawned job resources is blocked while the workflow is executing
Overall Status
A workflow job is marked as failed if:- A spawned job fails without a failure handler (no
failure_nodesoralways_nodeslink) - A spawned job is canceled without error handling
- All job failures have error handling paths
Notifications
Workflow job templates can be associated with notification templates. Notification bodies contain:- Status of the workflow itself
- Status of all spawned jobs
Simultaneous Runs
Workflows support simultaneous job runs controlled by theallow_simultaneous field:
- Disabled by default
- Enable carefully - performance boost only manifests when a large portion of contained jobs allow simultaneous runs
- Otherwise, expect long-running workflows due to jobs in pending state
Copy and Relaunch
Copying Workflows
POST to/workflow_job_templates/<id>/copy/ to create a copy with:
- Identical fields (description,
extra_vars, survey fields) - Copied workflow nodes and topology
- Name appended with copy indicator (e.g.,
'copy_from_name@10:30:00 am') - Null values for resources the user lacks access to
- Schedules and notification templates NOT copied
A workflow job template can be copied if the user has permission to add an equivalent workflow job template.
Relaunching Workflows
POST to/workflow_jobs/<id>/relaunch/ to relaunch:
- Original workflow job’s prompts re-applied to the template
- Creates new workflow job
- New job is triggered to run
- Survey password-type answers are redacted
DAG Structure
Workflows enforce a Directed Acyclic Graph (DAG) structure:- Connect nodes via
/workflow_job_template_nodes/<id>/*_nodes/endpoints *can besuccess,failure, oralways- Cycle restriction is enforced - cycles are not allowed
Best Practices
Error Handling
Always provide failure paths for critical jobs to prevent workflow failures
Node Naming
Use meaningful identifiers for workflow nodes to track job execution
Artifact Usage
Use artifacts to pass data between jobs instead of external storage
Testing
Test workflows with non-trivial topologies including multiple decision trees