[英]ansible - loop through fact and process each set of values
I have set a fact我已经设定了一个事实
set_fact:
props: "{{ parse_result.stdout | from_json }}"
The fact looks something like this:事实看起来是这样的:
{
"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
}
I want to loop through the fact and process each set of build_name and build_number.我想遍历事实并处理每组 build_name 和 build_number。 I have tried the below code, but sometimes it would throw me an error like 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'build_definition_name'.
我已经尝试了下面的代码,但有时它会给我一个错误,比如“ansible.utils.unsafe_proxy.AnsibleUnsafeText 对象”没有属性“build_definition_name”。 What am I doing wrong?
我究竟做错了什么?
my_deploy_module:
build_name: "{{ item.build_name }}"
build_number: "{{ item.build_number }}"
with_items: "{{ props }}"
I came to find answer to my own question in this post:我在这篇文章中找到了我自己问题的答案:
https://serverfault.com/questions/927855/ansible-loop-over-custom-facts https://serverfault.com/questions/927855/ansible-loop-over-custom-facts
Here is the syntax:这是语法:
my_deploy_module:
build_name: "{{ item.build_name }}"
build_number: "{{ item.build_number }}"
with_items: "{{ props | json_query('[*]') | flatten }}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.