I can successfully fetch a file with an explicit src. However, when I try 
to use with_items, I am getting a "remote file does not exist" error.

It doesn't matter whether I use a hard-coded list for with_items or a 
variable.

Here is the playbook:

---
- hosts: '{{ hosts }}'
  tasks:
  - name: List output files
    shell: bash -lc "ls -1 
/opt/appbin/elasticsearch/support-diagnostics.*.tar.gz"
    register: resultfiles
  - debug: var=resultfiles
  - name: Fetch files
    action: fetch src=$item dest=/Users/jpotts/Desktop/diags/ flat=yes 
fail_on_missing=yes
    with_items:
      - "{{ resultfiles.stdout_lines }}"

And here is the output:

(ansible)Metaversant:ansible jpotts$ ansible-playbook runDiagnostics.yml --
extra-vars "hosts=xldwcs01.someco.com"

PLAY [xldwcs01.someco.com] 
*************************************************** 

GATHERING FACTS 
*************************************************************** 
ok: [xldwcs01.someco.com]

TASK: [List output files] 
***************************************************** 
changed: [xldwcs01.someco.com]

TASK: [debug var=resultfiles] 
************************************************* 
ok: [xldwcs01.someco.com] => {
    "resultfiles": {
        "changed": true, 
        "cmd": "bash -lc \"ls -1 
/opt/appbin/elasticsearch/support-diagnostics.*.tar.gz\"", 
        "delta": "0:00:00.040305", 
        "end": "2015-05-08 10:43:11.456619", 
        "invocation": {
            "module_args": "bash -lc \"ls -1 
/opt/appbin/elasticsearch/support-diagnostics.*.tar.gz\"", 
            "module_name": "shell"
        }, 
        "rc": 0, 
        "start": "2015-05-08 10:43:11.416314", 
        "stderr": "", 
        "stdout": 
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181150.tar.gz\n/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181232.tar.gz\n/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181319.tar.gz\n/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181634.tar.gz\n/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181958.tar.gz"
, 
        "stdout_lines": [
            
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181150.tar.gz"
, 
            
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181232.tar.gz"
, 
            
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181319.tar.gz"
, 
            
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181634.tar.gz"
, 
            
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181958.tar.gz"
        ], 
        "warnings": []
    }
}

TASK: [Fetch file] 
************************************************************ 
failed: [xldwcs01.someco.com] => (item=/opt/appbin/elasticsearch/support-
diagnostics.xldwcs01._local.20150507-181150.tar.gz) => {"failed": true, 
"file": "$item", "item": 
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181150.tar.gz"
}
msg: the remote file does not exist
failed: [xldwcs01.someco.com] => (item=/opt/appbin/elasticsearch/support-
diagnostics.xldwcs01._local.20150507-181232.tar.gz) => {"failed": true, 
"file": "$item", "item": 
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181232.tar.gz"
}
msg: the remote file does not exist
failed: [xldwcs01.someco.com] => (item=/opt/appbin/elasticsearch/support-
diagnostics.xldwcs01._local.20150507-181319.tar.gz) => {"failed": true, 
"file": "$item", "item": 
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181319.tar.gz"
}
msg: the remote file does not exist
failed: [xldwcs01.someco.com] => (item=/opt/appbin/elasticsearch/support-
diagnostics.xldwcs01._local.20150507-181634.tar.gz) => {"failed": true, 
"file": "$item", "item": 
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181634.tar.gz"
}
msg: the remote file does not exist
failed: [xldwcs01.someco.com] => (item=/opt/appbin/elasticsearch/support-
diagnostics.xldwcs01._local.20150507-181958.tar.gz) => {"failed": true, 
"file": "$item", "item": 
"/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.20150507-181958.tar.gz"
}
msg: the remote file does not exist

FATAL: all hosts have already failed -- aborting

PLAY RECAP 
******************************************************************** 
           to retry, use: --limit @/Users/jpotts/runDiagnostics.retry

xldwcs01.someco.com       : ok=3    changed=1    unreachable=0    failed=1

I have also tried removing the variable by using the following task, which 
fails similarly:
  - name: Fetch specific file
    fetch: src=$item dest=/Users/jpotts/Desktop/diags/ flat=yes 
fail_on_missing=yes
    with_items:
      - /opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local.
20150507-181958.tar.gz

If I use one of the file paths from the debug output as the explicit src, 
it works:
  - name: Fetch specific file
    fetch: src=/opt/appbin/elasticsearch/support-diagnostics.xldwcs01._local
.20150507-181958.tar.gz dest=/Users/jpotts/Desktop/diags/ flat=yes 
fail_on_missing=yes

This is Ansible 1.8.2 on Mac OS X.

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/cc40c411-269d-4d9e-bc26-1b6833e20724%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to