Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Ansible inventory in one remote machine using command-line

You can specify inventory file host path or comma separated host list. Except “localhost”, you can always specify a inventory using “-i INVENTORY” or –inventory=INVENTORY.

Also, there are two default groups: all and ungrouped. “all” contains every host of the inventory file host path or comma separated host list and “ungrouped” contains all hosts that don’t have another group aside from all.

Here is the example of one remote machine inventory using ansible adhoc program.

$ ansible all -i 10.7.8.9, -m setup -u usernmae -k -b
$ ansible all -i 10.7.8.9, -m yum -a "name=httpd state=installed" -u usernmae -k -b
$ ansible all -i 10.7.8.9,10.7.8.9, -m yum -a "name=httpd state=installed" -u usernmae -k -b

Here is the example of one remote machine inventory using ansible inventory

# content of inventory file
10.7.8.9

$ ansible-playbook -i inventory playbook.yaml -u usernmae -k -b
$ ansible-playbook -i inventory playbook.yaml -u usernmae -k -b
$ ansible-playbook -i inventory playbook.yaml -u usernmae -k -b