从远程服务器到Ansible主机的Ansible复制失败

从远程服务器到Ansible主机的Ansible复制失败,ansible,Ansible,我需要将最新的日志文件从远程linux服务器复制到ansible主机。这就是我迄今为止所尝试的 - 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 fil

我需要将最新的日志文件从远程linux服务器复制到ansible主机。这就是我迄今为止所尝试的

- 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

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

Ansible Copy将文件从Ansible主机复制到远程主机。改为使用Ansible fetch。

这一个有效,我必须使用fetch而不是copy从远程获取文件

 - 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