Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
775 views
in Technique[技术] by (71.8m points)

syntax - How does --inventory option in Ansible work when it is given value with a trailing comma?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is (now, at least) a documented feature. From the man page:

-i, --inventory, --inventory-file
specify inventory host path or comma separated host list. --inventory-file is deprecated

(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":

$ ansible -i 'hostname,' ...

and "load inventory from a file called hostname":

$ ansible -i '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..)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...