Skip to content

Instantly share code, notes, and snippets.

@deoren
Forked from alces/ansible_ad_hoc_inventories.md
Created February 10, 2019 22:02
Show Gist options
  • Save deoren/f29a67493337eaa763af59d86cbc82f4 to your computer and use it in GitHub Desktop.
Save deoren/f29a67493337eaa763af59d86cbc82f4 to your computer and use it in GitHub Desktop.
Using Ad-hoc Inventories in Ansible

In case you want to run ansible (or ansible-playbook) command against a set of hosts that makes sense only for one run, you can don't bother to create one-time inventory file, but simply define a comma-separated list of hosts as argument of --invertory option (or its short form that's simply -i) as follows:

ansible --inventory=myhost1,myhost2,myhost3 all -m setup -a 'filter=*name*'

(note that all in this command line stands for the target hostname)

If you have only one host to run your playbook against, your inventory string must ends with , (because otherwise Ansible would interpret it as a name of inventory file, not a hosts' list) for example:

ansible-playbook -i myhost, all -a 'uname -a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment