Launching a job template
Before you begin
Do the following steps to include event attributes in the Ansible Tower's job or workflow template:
- Log on to Ansible Tower.
- Go to the Resources > Templates section and open the job template or the workflow template that you want to launch via the automation policy.
In the EXTRA VARIABLES section, include the variables and their values as per the template requirements.
For example, if a template contains the action to stop an EC2 instance, specify the instance ID and the region for the instance in the following format:{
"instance_ids": [
"i-0bb9cc75035405998"
],
"region": "us-east-1"
}
}For more information about the job templates and extra variables, see the Ansible Tower documentation.
To add Launch a Job Template action to a policy
- In the BMC Helix Intelligent Automation console, click Policies and the click Create Automation Policy.
- In the Policy Information section, enter a unique name and an optional description for the policy.
- Select Manual or Automatic depending upon whether you want to execute the policy manually or automatically based on the incoming events.
- In the Trigger section, click Browse and perform one of the following steps to select an event:
- From the Select Event Type tab, select an existing event type, and click Done.
On the Paste Event JSON tab, enter event in the JSON format, and click Done.
Sample event for launching a job template"tags": {
"event_type": "STOP_EC2_INSTANCE",
"region": "ap-southwest",
"instance_ids": ["i-05rab782b1f3770ct"]
}The event contains the following details:
- region is the location in which the instance to be shut down is located.
- instance_ids is the ID for the instance that you want to stop.
In the Trigger Condition text box, build the following expression to match the trigger condition to the event:
( tags.event_type == STOP_EC2_INSTANCE ) && ( tags.event.region == ap-southwest ) && ( tags.event.instance_ids == i-05rab782b1f3770ct )To understand the expression syntax, see the Trigger condition expressions section in Creating-automation-policies.
- To add action to the policy, click Add Action and perform the following steps by using the action wizard:
- From the Pick an automation tool section, click the connector name.
Only configured connectors are displayed here. The wizard takes you to the next step to select an action. - Click Sync Actions.
All job template and workflow template actions in your Ansible Tower instance appear. - Click Select against the Launch a Job Template action.
The wizard takes you to the next step to configure an action. - Provide the following information:
In Request body, enter the region and instance ID in the following format:
Sample request body for stopping an AWS EC2 instance{
"extra_vars": {
"instance_ids": [
"i-0bb9cc75035405998"
],
"region": "us-east-1"
}
}Replace <region> with the region in which the instance ID is located and instanceID with the ID of the instance that you want to stop by launching this template. The <region> and <instanceID> variables should match the variables in the Ansible template.
- In Template Id, enter the ID of the template that you want to launch.
- Click Done.
The added action appears in the Action Configuration section on the Create Automation Policies page.
- From the Pick an automation tool section, click the connector name.
- In the Estimated Savings section, enter an approximate time (in minutes) and money (in USD) that you may save by automating this action.
- Select Publish Policy and click Save to publish the policy.