Launching a job template
The Launch a Job Template action launches a specified job template from the Ansible Tower server. This template contains actions that are executed when the template is launched. For example, a template can contain action to stop an Amazon EC2 instance.
You specify this action while creating a policy.
While creating an action, you can use an event stored in the BMC Helix Intelligent Automation database or provide an event in a JSON format.
Important
The process described in this topic is for one of the Ansible Tower actions supported by BMC Helix Intelligent Automation. Use the steps in this topic to add any Ansible Tower actions while creating a policy.
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" } }
Note
If you want to pass any extra variables to scripts in Ansible Tower, you must select the Prompt on Launch option in Ansible Tower.
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 andinstanceID
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.
Comments
The note below is not clear, it needs to say specifically that if you want to pass variables to scripts in ansible tower, you must check the check box "Prompt on Launch" in the extra variables section of the job template.
Note
The extra variables in the request body (specified while adding an action) get overridden in Ansible Tower only if the Prompt on Launch option is enabled in Ansible Tower.
Hi Jon,
Updated this note. Will work with you for any other feedback that you have, Thanks!
Log in or register to comment.