我有这个结构
hosts
host_vars/server-foo/public.yml
group_vars/staging/public.yml
Run Code Online (Sandbox Code Playgroud)
在hosts文件中我已经定义了这样一个组
[staging]
server-foo
Run Code Online (Sandbox Code Playgroud)
我试图定义一个只适用于的变量server-foo,所以我将该行添加到文件中host_vars/server-foo/public.yml
bar: true
Run Code Online (Sandbox Code Playgroud)
当我尝试运行剧本时,我得到一个错误
fatal: [staging-accounts] => error while evaluating conditional: bar
Run Code Online (Sandbox Code Playgroud)
如果我添加bar: true到group_vars/staging/public.yml,则将变量的回升没有任何问题.
我有什么想法吗?我相信我一直在遵循ansible建议的方法来定义主机特定变量.
定义的结构是正确的,host_vars/<server>/public.yml应该被拾取.确保<server>文件夹名称与清单文件中的服务器条目相同.例如,如果清单中有IP地址,但域名作为文件夹名称则不起作用,则必须匹配.