Ansible set_fact 输出

Ansible set_fact output

我需要字符串或目标路径作为输出并将其用于其他任务,但显示的输出不同。 这是寄存器输出

ok: [localhost] => {
    "msg": {
        "changed": true,
        "msg": "All items completed",
        "results": [
            {
                "ansible_loop_var": "item",
                "changed": true,
                "checksum": "b045e5836bbd01d9c6dd2b7426afb5d1c8957b30",
                "dest": "/home/ec2-user/bb/Data-1.1.tar.gz",
                "failed": false,
                "invocation": {
                    "module_args": {
                        "_original_basename": null,
                        "attributes": null,
                        "backup": false,
                        "checksum": null,
                        "content": null,
                        "delimiter": null,
                        "dest": "/home/ec2-user/bb/Data-1.1.tar.gz",
                        "directory_mode": null,
                        "follow": false,
                        "force": true,
                        "group": null,
                        "local_follow": null,
                        "mode": null,
                        "owner": null,
                        "regexp": null,
                        "remote_src": true,
                        "selevel": null,
                        "serole": null,
                        "setype": null,
                        "seuser": null,
                        "src": "/home/ec2-user/aa/Data-1.1.tar.gz",
                        "unsafe_writes": null,
                        "validate": null
                    }
                },
                "item": "/home/ec2-user/aa/Data-1.1.tar.gz",
                "md5sum": "df9309334454cc3ceac9a6ac8fea8989",
                "src": "/home/ec2-user/aa/Data-1.1.tar.gz"

我使用下面的任务来显示目标路径

     - set_fact:
          filefact: "{{ output.results | map(attribute='item') | string }}"
     - debug:
          msg: "{{ filefact }}"

显示的输出是

ok: [localhost] => {
    "msg": "<generator object do_map at 0x7f59539f01e0>"

我会写:

 - set_fact:
      filefact: "{{ filefact | default([]) + [output.results.item] }}"
 - debug:
      msg: "{{ filefact }}"

正确的语法,按照您的输出应该是:

- set_fact:
    filefact: "{{ filefact | default([]) + [output.results[0].item] }}"

- set_fact:
    filefact: "{{ filefact | default([]) + [item.item] }}"
  loop: "{{ output.results }}"