Executing ad-hoc commands
One of the simplest operations that we can do with Ansible is to execute ad-hoc commands, so let's go ahead and execute a command on the host that we added in the inventory.
How to do it...
To execute an ad-hoc command on any host, we need to do the following:
- We need to go to the
Inventories
tab from the top navigation bar and select thecookbook inventory
. - Once the inventory section opens up, we need to go to the
Hosts
tab and select the host on which we want to execute the command. - After selecting the host, click on the
RUN COMMANDS
button. - A form for executing commands will open up. We can choose the module to execute the command. For this example, we will select the shell module from the module dropdown and provide the command in the
ARGUMENTS
field. - We have to provide a credential so that Ansible can execute the command. We can click on the lens icon in the machine credential field and select the credential that we created in the recipe Adding a machine credential...