Using results from a loop

Hi -

I’m trying to use the results from the find module while also using with_items. I can’t figure out how to extract just the paths from the first task to be able to use as input for the second task. Has anyone else done this? Can you clue me into the magic of how to do it? Thanks in advance!

- name: find adc norm files
  find:
    paths: "{{appdataRoot}}/svn/swiftmq_configs/{{oldHost}}/{{item.router_name}}/adcnorm/"
    patterns: "*.xml"
    use_regex: no
  with_items: "{{routers}}"
  delegate_to: localhost
  become: false
  register: adcFiles

- name: copy adc norm files to remote host
  copy:
    src: "{{item.1.path}}"
    dest: "{{smq_path}}/config/{{item.0.router_name}}/adcnorm/"
    mode: 0755
    follow: yes
    owner: appuser
    group: appuser
  with_nested:
    - "{{routers}}"
    - "{{adcFiles.results|flatten}}"


Impossible to tell without knowing what your data looks like. Can you add a debug statement for those vars (adcFiles and routers) in between the tasks? If those structures are clear we might be able to help.

Hi Dick -

Here’s the debug. I’ve shortened it for brevity. Thanks in advance for your help!

{
  "changed": false,
  "_ansible_verbose_always": true,
  "adcFiles": {
    "msg": "All items completed",
    "changed": false,
    "results": [
      {
        "files": [
          {
            "uid": 494,
            "woth": false,
            "mtime": 1560982851.643664,
            "inode": 9614,
            "isgid": false,
            "size": 1034,
            "roth": true,
            "isuid": false,
            "isreg": true,
            "pw_name": "awx",
            "gid": 1000,
            "ischr": false,
            "wusr": true,
            "xoth": false,
            "islnk": false,
            "nlink": 1,
            "issock": false,
            "rgrp": true,
            "gr_name": "awx",
            "path": "/opt/appdata/svn/swiftmq_configs/fr1ngsmpp06/fr1ngsmpp06_60105/adcnorm/adcnorm.xml",
            "xusr": false,
            "atime": 1560982851.643664,
            "isdir": false,
            "ctime": 1560982851.643664,
            "wgrp": false,
            "xgrp": false,
            "dev": 64772,
            "isblk": false,
            "isfifo": false,
            "mode": "0644",
            "rusr": true
          },
          {
            "uid": 494,
            "woth": false,
            "mtime": 1560982851.6446638,
            "inode": 9615,
            "isgid": false,
            "size": 810,
            "roth": true,
            "isuid": false,
            "isreg": true,
            "pw_name": "awx",
            "gid": 1000,
            "ischr": false,
            "wusr": true,
            "xoth": false,
            "islnk": false,
            "nlink": 1,
            "issock": false,
            "rgrp": true,
            "gr_name": "awx",
            "path": "/opt/appdata/svn/swiftmq_configs/fr1ngsmpp06/fr1ngsmpp06_60105/adcnorm/2sms_adcnorm.xml",
            "xusr": false,
            "atime": 1560982851.6446638,
            "isdir": false,
            "ctime": 1560982851.6446638,
            "wgrp": false,
            "xgrp": false,
            "dev": 64772,
            "isblk": false,
            "isfifo": false,
            "mode": "0644",
            "rusr": true
          }
        ],
        "_ansible_parsed": true,
        "changed": false,
        "_ansible_no_log": false,
        "_ansible_delegated_vars": {
          "ansible_delegated_host": "localhost",
          "ansible_host": "localhost"
        },
        "_ansible_item_result": true,
        "msg": "",
        "failed": false,
        "examined": 14,
        "item": {
          "plainsocketListenerPort": xxx,
          "layer": "protocol",
          "maxheap": "2048M",
          "mailbridgeVersion": "2.0.3",
          "retry_enabled": "n",
          "smpp_enabled": "y",
          "hostname": "fr1ngsmpp06-rhel6",
          "configOnLocal": true,
          "version": "9.7.3_unlimited",
          "bigmsg_enabled": "n",
          "smppVersion": "2.1.4",
          "amqp_enabled": "n",
          "directoryConnectorName2": "none",
          "java_version": "1.8.0_121",
          "brokerctrl": "xxx",
          "directoryConnectorName1": "none",
          "directoryConnectorHost2": "none",
          "directoryConnectorHost1": "none",
          "orderIDhost2": "xxx",
          "mailbridge_enabled": "n",
          "retryVersion": "1.1.0",
          "directorConnectorPort": xxx,
          "directoryListenerPort": xxx,
          "orderIDhost1": "xxx",
          "orderIDport2": xxx,
          "orderIDport1": xxx,
          "router_name": "fr1ngsmpp06_60105"
        },
        "invocation": {
          "module_args": {
            "paths": [
              "/opt/appdata/svn/swiftmq_configs/fr1ngsmpp06/fr1ngsmpp06_60105/adcnorm/"
            ],
            "excludes": null,
            "file_type": "file",
            "age": null,
            "contains": null,
            "recurse": false,
            "age_stamp": "mtime",
            "patterns": [
              "*.xml"
            ],
            "depth": null,
            "get_checksum": false,
            "use_regex": false,
            "follow": false,
            "hidden": false,
            "size": null
          }
        },
        "matched": 14,
        "_ansible_ignore_errors": null,
        "_ansible_item_label": {
          "plainsocketListenerPort": 50105,
          "layer": "protocol",
          "maxheap": "2048M",
          "mailbridgeVersion": "2.0.3",
          "retry_enabled": "n",
          "smpp_enabled": "y",
          "hostname": "fr1ngsmpp06-rhel6",
          "configOnLocal": true,
          "version": "9.7.3_unlimited",
          "bigmsg_enabled": "n",
          "smppVersion": "2.1.4",
          "amqp_enabled": "n",
          "directoryConnectorName2": "none",
          "java_version": "1.8.0_121",
          "brokerctrl": "xxx",
          "directoryConnectorName1": "none",
          "directoryConnectorHost2": "none",
          "directoryConnectorHost1": "none",
          "orderIDhost2": "xxx",
          "mailbridge_enabled": "n",
          "retryVersion": "1.1.0",
          "directorConnectorPort": xxx,
          "directoryListenerPort": xxx,
          "orderIDhost1": "xxx",
          "orderIDport2": xxx,
          "orderIDport1": xxx,
          "router_name": "fr1ngsmpp06_60105"
        }
      }
    ]
  },
  "_ansible_no_log": false
}