Ansible AWX Job Templates¶
Let's quickly review the difference between:
- Playbook: The actual yaml file that you create in code.
- Job Template: The opinionated way a given playbook is ran.
- Workflow Template: A sequence or flow of job templates and other tasks.
- Job: An instance of a running task based on a job or workflow template.
In Ansible AWX, a job template combines:
- A playbook, provided via a project
- An inventory (list of targets)
- Necessary credentials (SSH keys, passwords, etc.)
- Any additional
- Variables
- Forks
- Limit
- Tags
The job template is essentially a predefined configuration that sets up everything necessary to run a particular playbook, so that it is "ready-to-launch".
Examples:
- Run add_vlan.yml for coca-cola switch
- Run add_vlan.yml for pepsi switch
- Run update_fw.yml with a bastion host
The primary idea is you can choose:
- What is predefined
- What can be updated at runtime
Basic Job Templates Features¶
- NAME: Give your Job Template a descriptive name.
- DESCRIPTION Add any helpful description.
- JOB TYPE: "Run"by default, but can be check mode.
- INVENTORY: Choose the inventory you want to run this playbook against.
- PROJECT: Select the project that contains your playbook.
- PLAYBOOK: The playbooks available in that project, this is all "yaml" files will show.
- CREDENTIAL: Add the necessary credentials to connect to your hosts.
- Variables: If your playbook requires additional variables.
- Survey - If you wish to prompt the user for variables.
- Limit: In Ansible, the "limit" parameter restricts the playbook run to a subset of hosts.
- Fork: In Ansible, the "fork" parameter determines the number of parallel processes (or hosts) the playbook will run against simultaneously.
- Other - There are several options available, like enabling verbose mode, forcing a fresh project update before execution, etc.
Demo the creation of job templates with playbooks, adding variables, prompting variables, etc.
Demo the running of jobs from a specific job template and job templates list view.
Basic Job Templates Features - LAB¶
For all labs, use the following, unless otherwise stated
- Inventory: Project Inventory
- Project:
ntcu [ssh]
Develop the following job templates:
-
Add hello world job template:
- name:
ntcu-hello-world - Playbook:
ansible/job-templates/hello-world.yml
- name:
-
Add print-variables job template:
- name:
print-variables-hardcoded - Playbook:
ansible/job-templates/print-vars.yml - Variables:
tenant: coca-cola
- name:
-
Add print-variables with extra vars job template:
- name:
print-variables-extravars - Playbook:
ansible/job-templates/print-vars.yml - Variables: Select "Prompt on Launch"
- name:
Advanced Templates Surveys¶
Demo the creation of surveys, limit, forks, relaunch.
Advanced Templates Surveys - LAB¶
Develop the following job templates:
-
Add coca-cola add vlan job template:
- name:
add-vlan-coca-cola - Playbook:
ansible/job-templates/add-vlan.yml - Variables:
tenant: coca-cola - Limit: Select "Prompt on Launch"
- Forks: 10
- Survey: question: Which vlan would you like to deploy?, Answer: vlan, Answer Type: Integer
- name:
-
Add pepsi add vlan job template:
- name:
add-vlan-pepsi - Playbook:
ansible/job-templates/add-vlan.yml - Variables:
tenant: pepsi - Inventory: Standard Inventory
- Limit: Select "Prompt on Launch"
- Survey: question: Which vlan would you like to deploy?, Answer: vlan, Answer Type: Integer
- name: