Ansible Ad-hoc commands :
These commands uses /usr/bin/ansible command line tool to automate a single task on one or more linux machines. These are not reusable commands unlike using ansible playbook.
Syntax of these commands :
$ ansible [pattern] -m [module] -a [module-option]
Below are the commands:
- Details of your target machines/hosts can be mentioned in /etc/ansible/hosts file like below and when you will run/execute Ansible ad-hoc commands, it will fetch host details from this file and will make changes to those hosts
1) Ping Command :
We can execute ansible command by 2 ways.
Either by using /etc/ansible/hosts file or by creating inventory file which has entries of hosts on which you want to execute commands. Below are the two ways :
By Using hosts file :
By Using inventory file :
2) Command Module : This is used to run a command on your target machine
In the above example, we are executing “Date” command on our target host
3) Stat module : It is used to check the status of a file
4) Yum module : It is used to install a package at your target machine
5) User module : Used to add a new user to your target machine
6) Setup module : It is used to see all the system information of your target machine like CPU, memory, Network, Swap, kernel, etc
[osboxes@Controller ~]$ ansible all -m setup
The output of above command is too large to paste.