ansible - 遍历事实并处理每组值

ansible - loop through fact and process each set of values

我设定了一个事实

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 object' 没有属性 'build_definition_name'。我做错了什么?

my_deploy_module:
  build_name: "{{ item.build_name }}"
  build_number: "{{ item.build_number }}"
with_items: "{{ props }}"

我在这个 post:

中找到了我自己的问题的答案

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 }}"