Ansible Job template is used to incorporate the playbook in the web interface. Before start creating the template, you must create the playbook and keep it ready in the project path. We also need to create other objects like inventory, projects, and credentials to create a new job template. In this article, we will walk you through the job template creation and running the job template from AWX/Ansible Tower console.
1. Login to AWX/Ansible Tower console with admin privileges.
2. In this demo, we will be using the following inventory to create the ansible job template.
3. The following playbook will be used on the template. If you do not have the playbook, please create it in the following location. (If you use AWX and followed this tutorial )
[root@ansible-server ~]# cd /var/lib/awx/projects/UnixArena_Project/ [root@ansible-server UnixArena_Project]# [root@ansible-server UnixArena_Project]# ls -lrt total 4 -rw-r--r-- 1 root root 255 Nov 26 22:32 Unix_Arena_Demo_df.yaml [root@ansible-server UnixArena_Project]# cat Unix_Arena_Demo_df.yaml --- - hosts: all gather_facts: no tasks: - name: Root FS usage shell: df -h / |awk ' { print $5 } ' |grep -v Use register: dfroot - debug: msg: "System {{ inventory_hostname }}'s root FS utiliation is {{ dfroot.stdout }}" [root@ansible-server UnixArena_Project]#
4. Navigate to the template on AWX/Ansible Tower console and click on “+” to create a new template.
5. Enter the required template details. (*)
Here is how I have selected the credentials for the template.
6. Save the Ansible/AWX template. To check the disk utilization, we don’t need the privilege escalation.
7. Launch the ansible template.
10. Once the job is completed, you can see like below with disk utilization message.
We have successfully created the first ansible job template and ran successfully. Similarly, you could integrate many playbooks into Ansible Tower/AWX.
Leave a Reply