我想将此配置与清单插件一起使用
# test_inventory_xxx.yml
plugin: cloudscale # or openstack or ...
inventory_hostname: &inventory_hostname_value uuid
compose:
setting_of_inventory_hostname: *inventory_hostname_value
我没有错误,但未设置该值。这是有效的Yaml。 (至少我的检查者和我自己都看不到错误。
所以我决定通过使用构造的插件来简化它,这是标准的:
# inventory_constructed.yaml
plugin: constructed
# add variables to existing inventory
keyed_groups:
- key: from_inventory
prefix: inventory
parent_group: &common_parent_group test_group_1
compose:
var_from_constructed: 1233456789
also_from_constr: "'also'" # must be in quotes 2x!
some_from_constr: &ref1 1234567777
ref_from_constr: *ref1 # this works fine
ref_to_test: *common_parent_group # <--- this line returns an error
strict: yes
现在我得到了错误:Could not set ref_to_test for host my_host: 'test_group_1' is undefined
但是,当我取消标记行的注释时,它就会通过。 (ref&common_parent_group仍被定义,但未与* common_parent_group一起使用。)为什么在一种情况下未定义test_group_1
,而在另一种情况下未定义?
如何复制:ansible -i some_of/your_inventory -i inventory_constructed.yaml -m debug -a var=vars
我做错了什么?还是还有什么问题?
((我坚信这是一项缺少的功能,因此https://github.com/ansible/ansible/issues/69043中的原始信息)
[似乎parent_group
接受文字字符串,而ref_to_test
接受Jinja2表达式(因为它在compose
下)。如果您编写,则应该以相同的方式失败
ref_to_test: test_group_1
因为test_group_1
根本不是Jinja2变量。您必须写
ref_to_test: "'test_group_1'"
就像上面一样,因此Jinja2看到'test_group_1'
这是一个文字字符串。这也意味着您不能使用别名,因为parent_group
不会使用Jinja2评估其内容,因此其内容中不应包含引号。