我已经设定了一个事实
set_fact:
props: "{{ parse_result.stdout | from_json }}"
事实看起来像这样:
{
"changed": false,
"ansible_facts": {
"props": [
{
"build_number": "1.0.0.2",
"build_name": "AppXYZ"
},
{
"build_number": "1.2.0.2",
"build_name": "AppABC"
}
]
},
"_ansible_no_log": false
}
我想遍历事实并处理每组build_name和build_number。我尝试了以下代码,但有时会抛出类似“ ansible.utils.unsafe_proxy.AnsibleUnsafeText对象”的错误,但没有属性“ build_definition_name”。我在做什么错了?
my_deploy_module:
build_name: "{{ item.build_name }}"
build_number: "{{ item.build_number }}"
with_items: "{{ props }}"
答案 0 :(得分:0)
我在这篇文章中找到了我自己的问题的答案:
https://serverfault.com/questions/927855/ansible-loop-over-custom-facts
语法如下:
my_deploy_module:
build_name: "{{ item.build_name }}"
build_number: "{{ item.build_number }}"
with_items: "{{ props | json_query('[*]') | flatten }}"