Ansible AWX Workflow Templates¶
Job templates create an opinionated way to run an Ansible playbook that is "ready-to-launch". Logic could be built into playbooks, however, providing composable parts has it's advantageous to expose different parts to many user for their various use cases. Additionally, an actual approval system is a valuable tool within a workflow.
Workflow Templates Overview¶
Workflow Templates in Ansible AWX are a predefined series of interconnected tasks or jobs. Instead of executing a single playbook or task, a Workflow Template allows us to design more intricate processes with conditional branching, pauses, and connections between multiple tasks.
- Automation Capabilities: Using Workflow Templates, users can sequence different tasks in a specific order, allowing for the execution of complex operational tasks.
- Organizational Benefits: Workflow Templates help encapsulate and represent a sequence of operations that mirror real-world processes. It's like documenting your operations but with the added advantage of direct execution.
What are the differences between a Job Template and a Workflow Template.
- A Job Template is a definition and set of parameters for running an Ansible job. It’s the way to take a playbook and make it easily runnable by your team, at any time, without entering any additional data.
- While a Job Template focuses on a single playbook or operation, a Workflow Template is all about chaining operations or conditional execution of operations.
Example Workflows:
- Multi-stage Deployment: Imagine a scenario where you want to deploy an application across multiple environments. With Workflow Templates, you can create a process that deploys to a development environment, runs tests, and if successful, deploys to production.
- Infrastructure Provisioning and Setup: Another example could be the provisioning of a new switch, followed by setting up monitoring for it, and notifying the IT team. All these tasks can be chained in a Workflow Template.
- Conditional Operations: Say you have a database backup job. Using Workflow Templates, you can create a process that drains the plane of the primary router, and only if that's successful, it moves to the second device, if not, it sends a failure notification.
Creating a Workflow Template¶
Let's review some key features of a workflow template and demo them.
- Nodes: Job Templates, Project Syncs, and Inventory Syncs - Understanding the different types of nodes and their roles.
- Edges: Success, Failure, and Always - How to dictate the flow of the workflow based on the outcome of nodes.
Workflow Templates Overview - LAB¶
Perform the following to create a workflow
- Create a Job Template from
check-fw-request.yml,notify-servicenow.yml,push-config.yml - The
check-fw-request.ymlis expecting a variable calledprotocol- The
protocolvariable should be one of['https', 'ssh', 'ipsec', 'http', 'telnet', 'gre']
- The
- The workflow template should start with the playbook
check-fw-request.yml- On success run
push-config.yml - On failure run
notify-servicenow.yml
- On success run
Info
Use your preferred inventory and other features. Also, consider that you need the ability to send in a protocol within your request.
Workflow Template Advanced¶
Let's review some additional features of a workflow template and demo them.
- Approval Nodes - The concept of manual intervention and approvals in workflows.
- Workflow-level Variables vs. Node-level Variables - Differentiate between variables scoped to the entire workflow versus those specific to nodes.
Workflow Template Advanced - LAB¶
Within the already created workflow template
- Update a step to ensure that the project and inventory used.
- Add an approval step before the
push-config.ymlfile is pushed.
Workflow Template Additional Features¶
Though outside the scope of this training, let's review some additional features provided in Workflow Templates.
- Convergence (Multiple workflows converging into one) - The idea of multiple paths converging and its use-cases.
- Using Webhooks with Workflows - How to integrate external triggers via webhooks.
- Nesting Workflow Templates - The benefits and considerations of having workflows within workflows.