我正在尝试使用with_items
指定要传递给自定义 ansible 模块的键/值对列表。
当键或值字符串具有类似列表的格式时,就会出现问题。例如。,"[('a', 'b'), ('c', 'd')]"
。在这种情况下with_items
大概将字符串转换为列表并对我的配置造成严重破坏。
重现的最小示例(我正在使用debug
模块,但对于自定义模块,行为是相同的):
- name: with_items_test
debug:
msg: "{{ item.value }}"
with_items:
- { value: "[('a', 'b'), ('c', 'd')]" }
TASK [with_items_test] *********************************************************
ok: [localhost] => (item={u'value': u"[('a', 'b'), ('c', 'd')]"}) => {
"item": {
"value": "[('a', 'b'), ('c', 'd')]"
},
"msg": [
[
"a",
"b"
],
[
"c",
"d"
]
]
}
Without with_items
这样的字符串就可以很好地传递:
- name: with_items_test
debug:
msg: "[('a', 'b'), ('c', 'd')]"
TASK [with_items_test] *********************************************************
ok: [localhost] => {
"msg": "[('a', 'b'), ('c', 'd')]"
}