2017-06-14 84 views
0

我需要将最新的日志文件从远程Linux服务器复制到主管主机。这是我到目前为止所尝试的。从远程服务器复制到主管主机失败

- hosts: [host] 
    remote_user: root 
    tasks: 
    - name: Copy the file 
    command: bash -c "ls -rt | grep install | tail -n1" 
    register: result 
    args: 
     chdir: /root 
    - name: Copying the file 
    copy: 
     src: "/root/{{ result.stdout }}" 
     dest: /home 

但我收到以下错误。

TASK [Gathering Facts] ******************************************************************************************************************************************************************************************** 
ok 

TASK [Copy the file] ********************************************************************************************************************************************************************************************** 
changed: => {"changed": true, "cmd": ["bash", "-c", "ls -rt | grep install | tail -n1"], "delta": "0:00:00.011388", "end": "2017-06-14 07:53:26.475344", "rc": 0, "start": "2017-06-14 07:53:26.463956", "stderr": "", "stdout": "install.20170614-051027.log", "stdout_lines": ["install.20170614-051027.log"], "warnings": []} 

TASK [Copying the file] ******************************************************************************************************************************************************************************************* 
fatal: FAILED! => {"changed": false, "failed": true, "msg": "Unable to find 'install.20170614-051027.log' in expected paths."} 


PLAY RECAP ******************************************************************************************************************************************************************************************************** 
      : ok=2 changed=1 unreachable=0 failed=1 

但是那个文件就在那里。请帮我解决这个问题。

回答

0

这一个工程,我必须使用抓取而不是复制从远程获取文件。

- name: Copy the file 
    command: bash -c "ls -rt | grep install | tail -n1" 
    register: result 
    args: 
     chdir: /root 
    - name: Copying the file 
    fetch: 
     src: "/root/{{ result.stdout }}" 
     dest: /home 
     flat: yes 
相关问题