当我使用变量时,Fetch不会传输

时间:2016-07-23 17:40:46

标签: ansible ansible-playbook

当我使用变量并获取消息为“msg”时,

获取模块不传输文件:“远程文件不存在,不传输,忽略”。但文件退出源目录。如果有任何问题,请提出建议。

ansible 2.1.0.0

   ---
    - hosts: host_A
    become_user: yes
    gather_facts: no
    tasks:
    - name: list files
      shell: ls -1 /root/stuff/install.1_comiskey-v01
      register: dumpfiles 
    -debug: var=dumpfiles

    - name: fetch files 
      fetch: src={{item}} dest=/tmp/fetched/  flat=yes  
      with_items: ('{{dumpfiles.stdout_lines}}')  
      register: test
    - debug: var=test 

输出:

     TASK [fetch files]                                                                              
     *************************************************************
     ok: [10.1.31.82] => (item=('[u'/root/stuff/install.1_comiskey-v01',u'/root/stuff/install.1_comiskey-v02']'))

     TASK [debug] *******************************************************************
     ok: [10.1.31.82] => {
     "test": {
     "changed": false, 
     "msg": "All items completed", 
     "results": [
            {
                "_ansible_item_result": true, 
                "_ansible_no_log": false, 
                "changed": false, 
                "file": "('[u'/root/stuff/install.1_comiskey-v01', u'/root/stuff/install.1_comiskey-v02']')", 
                "invocation": {
                    "module_args": {
                        "dest": "/tmp/fetched/", 
                        "flat": "yes", 
                        "src": "('[u'/root/stuff/install.1_comiskey-v01', u'/root/stuff/install.1_comiskey-v02']')"
                        }, 
                    "module_name": "fetch"
                    }, 
                "item": "('[u'/root/stuff/install.1_comiskey-v01', u'/root/stuff/install.1_comiskey-v02']')", 
                "msg": "the remote file does not exist, not transferring, ignored"
            }
        ]
        }
        }

1 个答案:

答案 0 :(得分:1)

从with_items中删除括号。您可以注意到调试输出中的项变量不正确。