当 Ansible 中的 --inventory 选项以逗号结尾时,它如何工作?

tec*_*raf 5 syntax ansible

手册页ansible并将选项ansible-playbook 定义为:-i

-i PATH, --inventory=PATH
       The PATH to the inventory hosts file, which defaults to
       /etc/ansible/hosts.
Run Code Online (Sandbox Code Playgroud)

然而,要在本地系统上运行,示例中使用以下语法:

ansible -i "localhost," -c local -m ping localhost
Run Code Online (Sandbox Code Playgroud)

末尾带有逗号的到底是什么"localhost,"(否则它被视为文件名)以及它与 有何关系PATH

sup*_*cuo 5

这是(至少现在)已记录的功能。从man页面

-i, --inventory, --inventory-file
指定清单主机路径或逗号分隔的主机列表。--inventory-file 已弃用

(强调已添加)

手册中仍然没有提到“逗号分隔的主机列表”意味着即使“列表”是单个项目,您也需要添加逗号,以区分“目标名为hostname”的单个主机:

$ ansible -i 'hostname,' ...
Run Code Online (Sandbox Code Playgroud)

和“从名为”的文件加载库存hostname

$ ansible -i 'hostname,' ...
Run Code Online (Sandbox Code Playgroud)

如果有人有时间,也许您可​​以提交拉取请求来更改帮助文本来解释这一点(并在“逗号分隔”中添加连字符,但也许这只是我......)