Man pages for ansible
and ansible-playbook
define -i
option as:
-i PATH, --inventory=PATH
The PATH to the inventory hosts file, which defaults to
/etc/ansible/hosts.
Yet to run on a local system the following syntax is used in examples:
ansible -i "localhost," -c local -m ping localhost
What exactly is this "localhost,"
with comma at the end (otherwise it is treated as filename) and how does it relate to PATH
?
According to Michael DeHann, who created Ansible, the comma trick you're referring to is a hack that shouldn't be relied upon. It's a hack to run Ansible without an inventory file, for cases where you're going to run against localhost. That way you don't actually have to create an inventory file that just lists localhost.
This is (now, at least) a documented feature. From the
man
page:(emphasis added)
What's still not in the manual is that "comma separated host list" means that you need to add a comma even if the "list" is a single item, to distinguish between "target a single host called
hostname
":and "load inventory from a file called
hostname
":If anyone out there has time, maybe you could submit a pull request to change the help text to explain this (and to add a hyphen in "comma-separated", but maybe that's just me..)
Actually, when you want to run commands against a specific host, don't add
-i
, instead, run it in the following way:Use
-i
only to specify the path for dynamic inventory or hosts.