Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll 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
Rajesh Kumar
Follow me