如何在ansible中将文件从网络路径复制到控制器机器



假设我在网络路径中有一个文本文件

例如:\cr-ampd-a01.abcd.loc\BulkFolder\textfile.txt

如何在ansible中将该文件复制到我的控制器机器

注意:我可以通过(WIN+R和该路径(访问它,然后它会弹出供凭据访问。

这是带有win_copy的示例代码

- name: copy from network to controller
win_copy:
src: \cr-ampd-a01.abcd.locBulkFoldertextfile.txt
dest: C:TempOTWMastapps
remote_src: yes
become: yes
vars:
ansible_become_user: XXXUxxxxxx
ansible_become_pass: PasswordHere

此代码的错误是:无法复制src文件,因为它没有退出

另一个具有net_get

- name: copy from network to controller
net_get:
src: \cr-ampd-a01.abcd.locBulkFoldertextfile.txt
dest: C:TempOTWMastapps
ansible_network_os: "eos"
remote_src: True
become: True
vars:
ansible_become_user: XXXUxxxxxx
ansible_become_pass: PasswordHere

此处错误:必须在此主机上指定ansible_network_os

我该如何做到这一点

您尝试从CIFS资源中复制文件。我相对确信这不适用于copywin_copy,因为它们用于复制(物理(机器上的文件。因为CIFS是一种类似于HTTP和FTP的协议,所以您需要一个客户端来从远程机器获取文件。正如您所写的,您需要用一些凭据来标识自己,win_copy任务没有这个选项。

一种选择可以是-将网络设备安装到-例如-N:/或类似的位置,然后将win_copy与N:/source.txt一起使用-在这种情况下,N:-驱动器类似于机器上的C:/或D:/已知路径。看看win_share-https://docs.ansible.com/ansible/latest/modules/win_share_module.html

另一种选择是通过command: copy //server/path/file c:/file或robocopy等命令调用本地CIFS客户端,但这并不容易实现幂等。请参阅在windows命令行上将文件复制到网络计算机

net_get可用于从"网络设备"复制文件-请查看https://docs.ansible.com/ansible/latest/network/user_guide/platform_index.html#platform-支持的平台列表的选项。从列表中可以看出,net_get不支持从CIFS共享进行应对。

最新更新