dict中的Ansible组合数组

dict中的Ansible组合数组,ansible,Ansible,我有一个像这样的数组 tests: test01: state: 'enabled' objects: - 'A111' - 'B111' test02: state: 'enabled' objects: - 'C222' - 'D222' test03: state: 'enabled' objects: - 'E333' - 'F333' 如何在一个输出中

我有一个像这样的数组

tests:
  test01:
    state: 'enabled'
    objects: 
      - 'A111'
      - 'B111'
  test02:
    state: 'enabled'
    objects:
      - 'C222'
      - 'D222'
  test03:
    state: 'enabled'
    objects:
      - 'E333'
      - 'F333'
如何在一个输出中将数组“对象”组合在一起?结果应该是

"msg": "A111,B111,E333,F333,C222,D222"
这是你需要的吗

  - debug:
     msg: "{{(tests.test01.objects,tests.test02.objects,tests.test03.objects)|flatten|join('\n')|replace('\n', ',')}}"

确定:[本地主机]=>{ “味精”:“A111、B111、C222、D222、E333、F333” }

这是你需要的吗

  - debug:
     msg: "{{(tests.test01.objects,tests.test02.objects,tests.test03.objects)|flatten|join('\n')|replace('\n', ',')}}"

确定:[本地主机]=>{ “味精”:“A111、B111、C222、D222、E333、F333” }


这里是多行,但没有硬编码的项目

- set_fact:
    tests_dict: "{{ item }}"
  with_dict: "{{ tests }}"
  register: tests_items

- set_fact:
    tests_objects: "{{ tests_objects }} + {{ item.item.value.objects }}"
  with_items: "{{ tests_items.results }}"
  vars:
    tests_objects: []

- debug:
    msg: "{{ tests_objects | join(',') }}"
确定:[127.0.0.1]=>{ “msg”:“C222、D222、E333、F333、A111、B111”}


这里是多行,但没有硬编码的项目

- set_fact:
    tests_dict: "{{ item }}"
  with_dict: "{{ tests }}"
  register: tests_items

- set_fact:
    tests_objects: "{{ tests_objects }} + {{ item.item.value.objects }}"
  with_items: "{{ tests_items.results }}"
  vars:
    tests_objects: []

- debug:
    msg: "{{ tests_objects | join(',') }}"
确定:[127.0.0.1]=>{ “msg”:“C222、D222、E333、F333、A111、B111”}


不是真的。你的答案是数组,但我需要字符串。如果会有更多的测试,比如test04…testN,那会怎么样?不太可能。你的答案是数组,但我需要字符串。如果会有更多的测试,比如test04…testN呢?这可能真的值得一读,这一页讨论了所有tge修改变量的方法。这一页可能真的值得一读,这一页讨论了所有tge修改变量的方法