Ansible Ad hoc command is very easy to understand the basic on Ansible. Ad hoc command helps you to perform small tasks on group of servers. Tasks like reboot, restart any service, change file permission etc on bunch of servers. To perform any action using Ad hoc you need to use ‘/usr/bin/ansible’ command.
Hosts: Here hosts mean bunch of servers which we will define in Ansible inventory file. If we wan to perform and action to all hosts from inventory, use all or ‘*’. module_name: There are many modules available in Ansible. To list all the available modules execute mentoin command.
# ansible-doc -l
arguments: We need to pass the value according to your module and the value will be change as per your module. username: We will specifies the ansible user from which we want to execute the command. become: When we want to execute any operation with sudo privileges then we use become. By default value of become is false.
Note: If you will use -c option, then Ansible will do a dry run of the command. It will not execute or apply on the client nodes.