Skip to content

Instantly share code, notes, and snippets.

@alces
Last active September 2, 2022 07:17
Show Gist options
  • Save alces/f7e3de25d98a19550a4e4f97cabc2cf4 to your computer and use it in GitHub Desktop.
Save alces/f7e3de25d98a19550a4e4f97cabc2cf4 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