在hostvars中使用变量作为主机[重复]

问题描述 投票:-1回答:1

我这样使用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.

有没有办法在不需要使用弃用的东西的情况下实现同样的目标?

ansible
1个回答
0
投票

[重复]解决方案是:

{{ hostvars[item]['something'] }}
with_items: "{{ groups['myhost'] }}"
© www.soinside.com 2019 - 2024. All rights reserved.