Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lilongen/ebc11f69ae2ba48971c77527d5c02fab to your computer and use it in GitHub Desktop.
Save lilongen/ebc11f69ae2ba48971c77527d5c02fab to your computer and use it in GitHub Desktop.
How to run Ansible without specifying the inventory but the host directly?
Question:
. How to run Ansible without specifying the inventory but the host directly?
. Run a playbook or command with arbitrary host not in the inventory hosts list?
. run ansible with arbitrary host/ip without inventory?
Answer:
Surprisingly, the trick is to append a ,
The host parameter preceding the , can be either a hostname or an IPv4/v6 address.
ansible all -i example.com,
ansible all -i 93.184.216.119,
ansible-playbook -i example.com, playbook.yml # Requires 'hosts: all' in the playbook
@Bablzz
Copy link

Bablzz commented Feb 6, 2019

Good trick!

@hluaces
Copy link

hluaces commented Feb 8, 2019

Just to add some explanation to this: this is because <ip|host>, is being processed by the host_lists ansible inventory plugin which dynamically creates an inventory from a series of targets separated by commas. If there aren't commas on your target specification the plugin won't trigger and thus, won't create the inventory.

@queglay
Copy link

queglay commented Aug 17, 2019

I'm a bit unclear still on what is going on here. does this mean that example.com will be defined to reach 93.184.216.119?

@Aitozi
Copy link

Aitozi commented Aug 28, 2019

can this ansible all -i ip1,ip2-m shell -a "ifconfig" . be executed on two machine?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment