Abstract
| Goal | Run automated tasks on devices using plays and ad hoc commands. |
| Objectives |
|
| Sections |
|
| Lab |
Running Commands and Plays |
After completing this section, you should be able to run ad hoc commands to execute single, one-time tasks.
An ad hoc command is a single, manually run Ansible task that you want to perform quickly and do not need to save to run again later.
This is the form of an ad hoc command:
ansible host-pattern -m module [-a 'module arguments'] [-i inventory]
When module arguments are enclosed within single or double quote marks, the space that follows the -a option and the arguments is optional.
When are ad hoc commands useful? It depends on the module.
To enable the netconf service on a platform that supports it, run the following command:
[user@host ~]$ansible -m junos_netconfhost-identifier
To test Ansible connectivity and authentication to a managed resource (not ICMP), run the following command:
[user@host ~]$ansible -m pinghost-identifier
To determine if you can reach an IP address from a managed resource (using ICMP), run the following command:
[user@host ~]$ansible -m ios_pinghost-identifier-a "dest=ip-address"
You can pass arguments to modules with the -a option.
[user@host ~]$ansible -m vyos_command -a "commands='command'"host-identifier