What is Ansible ad hoc command?

Published: 23 November 2023
on channel: The Lazy SysAdmin
615
34

Using Ansible ad-hoc commands are a helpful feature that spares you from writing a whole playbook and let you run a single task on multiple hosts. These commands work well for short operations, such as verifying the status of a service on multiple hosts. But a playbook is usually a preferable option for more involved processes, such as software installations.

To perform an ad hoc command, enter a single line of command with the necessary arguments, like the desired module name and any others that need to be supplied.

An ad hoc command in Ansible has the following syntax:
ansible hosts -m module -a "arguments"

hosts is a comma-separated list of target hosts,
module is the name of the Ansible module to use, and
arguments are any arguments to be passed to the module.
For example, if you wanted to check the current date and time on a group of servers, you could use the date command with the shell module, like this:

ansible webservers -m shell -a "date"

The shell module would run the date command on all servers in the webservers group. Then, you’ll be able to see the output from each server in your console. It’s super easy and efficient!

PLEASE SUBSCRIBE :)
PLEASE HIT LIKE IF IT HELPED :)

GIVE SUPPORT -   / lazysysad  
BUY ME A COFFEE - https://www.buymeacoffee.com/lazysysad
PAYPAL - https://www.paypal.com/donate/?hosted...

Drop me your feedback and comments.

If this video helped you in any way, please like share and subscribe!

Thank you!!!


Watch video What is Ansible ad hoc command? online without registration, duration hours minute second in high quality. This video was added by user The Lazy SysAdmin 23 November 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 615 once and liked it 34 people.