Ansible - 从Windows远程共享中获取文件

时间:2017-07-06 12:16:51

标签: windows ansible shared-directory

我正在尝试从Windows DFS共享中获取一个文件到localhost(linux)以便稍后解析它。

该文件的路径类似于:\\ windows_host \ folder \ file

我正在尝试使用类似于此的fetch模块:

- name: Test hosts: all connection: local gather_facts: no tasks: - name: Fetching a file from a Windows DFS Share fetch: src: \\windows_host\folder\file dest: local_folder/file flat: yes

但是当我运行它时,它没有得到文件,如果我使用详细选项,它说:
“msg”:“远程文件不存在,不传输,忽略”

虽然文件存在于特定位置..所以我认为问题在于路径编码(我可能错了),我尝试了几种不同的格式,但到目前为止还没有运气。

有谁知道怎么做或我做错了什么?

无论如何,我们也非常感谢获取文件的其他方法 我不允许挂载共享或有任何服务(ftp / http / etc ..)返回文件

提前致谢

ValerioG

1 个答案:

答案 0 :(得分:0)

我实际上设法使用linux中的命令模块和smbclient命令使其工作。 如果有人需要类似的东西,下面的剧本对我有用。

---
- name: Test
  hosts: all
  connection: local
  gather_facts: no
  vars_files:
    - vault_with_AD_credentials.yaml

  tasks:
    - name: Getting the Exchange Data file from Windows Share
      run_once: yes
      command: smbclient '\\windows_host\share' -c 'lcd local_folder; cd remote_folder; get filename' -U {{ ad_username }}%{{ ad_password }}