How to run Ansible without hosts file

How to start Ansible without hosts file?

as:

$ ansible --"Some Options" IP -a 'uptime' 
+9
source share
3 answers

you can do like this:

 ansible all -i "<hostname-or-ip>," -a 'uptime' 

Note the end of the IP address, or it will be considered the host inventory file name.

Here is an example link:

 ansible all -i "192.168.33.100," -a 'uptime' 192.168.33.100 | SUCCESS | rc=0 >> 12:05:10 up 10 min, 1 user, load average: 0.46, 0.23, 0.08 
+17
source

Hosts can be accessed using three methods.

  • Using the inventory path in ansible.cfg, which by default is / etc / ansible / host

  • Using the hosts file

     ansible -i /tmp/hosts -a 'uptime' 
  • Use ip hosts as a comma separated list of hosts. Take care of the comma at the end of the list

     ansible -i "192.168.1.16,192.168.1.80:2222," -a 'uptime' 

From ansible --help you can get a description of the -i option

 -i INVENTORY, --inventory-file=INVENTORY specify inventory host path (default=/etc/ansible/hosts) or comma separated host list. 
+4
source

If you want to run the playbook at once or several, but not the entire list, you can try with -l | --limit "your.node.local"

 ansible-playbook -i inventory.hosts --limit your.node.local user.yml 
0
source

All Articles