Ansible jmespath。根据类型更改数组中的一个元素

Ansible jmespath。根据类型更改数组中的一个元素,ansible,jmespath,json-query,Ansible,Jmespath,Json Query,Im使用Ansible筛选器json\u查询 数据: 我想得到: [ { "path": "just_dir", }, { "path": "extend_dir", "order": "nginx" } ] 不工作。不幸的是,似乎无法合并到2个数组 Github问题: 在将其应用于json\u查询之前,您还需要添加一个from\u json过滤器 --- - hosts: localhost gather_facts: no vars:

Im使用Ansible筛选器json\u查询

数据:

我想得到:

[
  {
     "path": "just_dir",
  },
  {
     "path": "extend_dir",
     "order": "nginx"
  }
]

不工作。

不幸的是,似乎无法合并到2个数组

Github问题:

在将其应用于
json\u查询之前,您还需要添加一个
from\u json
过滤器

---
- hosts: localhost
  gather_facts: no
  vars:
    data: '[
      "just_dir",
      {
         "path": "extend_dir",
         "order": "nginx"
      }
    ]'
  tasks:
   - name: debug just_dir
     debug: msg="{{ data | from_json  | json_query(jmesquery) }}"
     vars:
       jmesquery: "[?type(@) == `string`].{path: @}"

   - name: debug Other data
     debug: msg="{{ data | from_json  | json_query(jmesquery) }}"
     vars:
       jmesquery: "[?type(@) == `object`]"
merage([?type(@) == `string`].{path: @}, [?type(@) == `object`])
---
- hosts: localhost
  gather_facts: no
  vars:
    data: '[
      "just_dir",
      {
         "path": "extend_dir",
         "order": "nginx"
      }
    ]'
  tasks:
   - name: debug just_dir
     debug: msg="{{ data | from_json  | json_query(jmesquery) }}"
     vars:
       jmesquery: "[?type(@) == `string`].{path: @}"

   - name: debug Other data
     debug: msg="{{ data | from_json  | json_query(jmesquery) }}"
     vars:
       jmesquery: "[?type(@) == `object`]"