这个问题在这里已有答案:
我这样使用hostvars:
{{ hostvars['host']['something'] }}
它工作正常。但是,我想为主机名使用变量名,所以我做了以下事情:
{{ hostvars[item]['something'] }}
with_items: groups['myhost']
它正在工作,但有一条警告信息:
[DEPRECATION WARNING]: Using bare variables is deprecated. Update your playbooks so that the environment value uses the full
variable syntax ('{{groups["myhost"]}}').
This feature will be removed in a future release. Deprecation warnings can be disabled
by setting deprecation_warnings=False in ansible.cfg.
有没有办法在不需要使用弃用的东西的情况下实现同样的目标?
[重复]解决方案是:
{{ hostvars[item]['something'] }}
with_items: "{{ groups['myhost'] }}"