Ansible无法从远程目录获取所有文件

时间:2019-05-07 09:56:38

标签: ansible

我正在将日志文件从远程Windows计算机复制到本地计算机。

这是我的Ansible-

- name: Debug Msg
  debug: msg="Copying logs at - {{ log_full_path }}"

- name: Debug Msg
  debug: msg="Copying logs from - {{ log_file }}"

- name: Getting directory of files
  win_shell: Get-ChildItem | where {!$_.PsIsContainer} | foreach { $_.Name }
  args:
    chdir: "{{ log_file }}"
  register: files_to_copy

- name: Fetch logs
  fetch: src={{ log_file }} dest={{ log_full_path }} fail_on_missing=yes validate_checksum=yes
  with_items: "{{ files_to_copy.stdout_lines }}"

当我通过python代码运行ansible时,它表明它正在正确复制文件,但在目标目录中看不到任何文件。

TASK [Debug Msg] ***************************************************************
ok: [win1] => {
    "msg": "Copying logs at - /tmp/cbl-logs/"
}

TASK [Debug Msg] ***************************************************************
ok: [win1] => {
    "msg": "Copying logs from - C:\\Users\\Administrator\\AppData\\Local\\Temp\\log_1557220483.4525"
}

TASK [Getting directory of files] **********************************************
changed: [win1]

TASK [Fetch logs] **************************************************************
ok: [win1] => (item=cbl_debug_1557220483607.cbllog)
ok: [win1] => (item=cbl_error_1557220483610.cbllog)
ok: [win1] => (item=cbl_info_1557220483608.cbllog)
ok: [win1] => (item=cbl_verbose_1557220483608.cbllog)
ok: [win1] => (item=cbl_warning_1557220483609.cbllog)

PLAY RECAP *********************************************************************
win1                       : ok=5    changed=1    unreachable=0    failed=0   

Checking /tmp/cbl-logs/ for copied log files - []

我不确定我在做什么错。任何帮助都非常感激

2 个答案:

答案 0 :(得分:0)

根据Ansible documentation,目的地将是这样

A directory to save the file into. For example, 
if the dest directory is /backup a src file named /etc/profile 
on host host.example.com, would be saved into /backup/host.example.com/etc/profile

因此/ tmp / cbl-logs / win1将成为您的目的地...

答案 1 :(得分:0)

所以我弄错了。我没有传递要复制的迭代中的文件名。

进行以下更改后,我可以运行它

之前:-

xsl:element

之后:-

type