Explore and understand the lab environment. This exercise will cover
Locating and understanding:
Running ad hoc commands via the Ansible Tower web UI
The first thing we need is an inventory of your managed hosts. This is the equivalent of an inventory file in Ansible Engine. There is a lot more to it (like dynamic inventories) but let’s start with the basics.
admin. The password will be provided by the instructor.
There will be one inventory, the Workshop Inventory. Click the Workshop Inventory then click the Hosts button
The inventory information at
~/lab_inventory/hosts was pre-loaded into the Ansible Tower Inventory as part of the provisioning process.
$ cat ~/lab_inventory/hosts [all:vars] ansible_user=student<X> ansible_ssh_pass=PASSWORD ansible_port=22 [web] node1 ansible_host=18.104.22.168 node2 ansible_host=22.214.171.124 node3 ansible_host=126.96.36.199 [control] ansible ansible_host=188.8.131.52
In your inventory the IP addresses will be different.
Now we will examine the credentials to access our managed hosts from Tower. As part of the provisioning process for this Ansible Workshop the Workshop Credential has already been setup.
In the RESOURCES menu choose Credentials. Now click on the Workshop Credential.
Note the following information:
|SSH PRIVATE KEY||
It is possible to run run ad hoc commands from Ansible Tower as well.
In the web UI go to RESOURCES → Inventories → Workshop Inventory
Click the HOSTS button to change into the hosts view and select the three hosts by ticking the boxes to the left of the host entries.
Click RUN COMMANDS. In the next screen you have to specify the ad hoc command:
|MACHINE CREDENTIAL||Workshop Credentials|
The simple ping module doesn’t need options. For other modules you need to supply the command to run as an argument. Try the command module to find the userid of the executing user using an ad hoc command.
After choosing the module to run, Tower will provide a link to the docs page for the module when clicking the question mark next to “Arguments”. This is handy, give it a try.
How about trying to get some secret information from the system? Try to print out /etc/shadow.
Expect an error!
Oops, the last one didn’t went well, all red.
Re-run the last ad hoc command but this time tick the ENABLE PRIVILEGE ESCALATION box.
As you see, this time it worked. For tasks that have to run as root you need to escalate the privileges. This is the same as the become: yes used in your Ansible Playbooks.
Okay, a small challenge: Run an ad hoc to make sure the package “tmux” is installed on all hosts. If unsure, consult the documentation either via the web UI as shown above or by running
[ansible@tower ~]$ ansible-doc yum on your Tower control host.
|ENABLE PRIVILEGE ESCALATION||✓|
The yellow output of the command indicates Ansible has actually done something (here it needed to install the package). If you run the ad hoc command a second time, the output will be green and inform you that the package was already installed. So yellow in Ansible doesn’t mean “be careful”… ;-).