2017-07-03 34 views
1

复制文件,所以我有一个ansible剧本如下:Ansible阳明从网络位置

#WINDOWS# 
--- 
- hosts: windows tasks: 

    - name: copy file 
    raw: '"net use M: "\\somemachinename\someLocation" /user:username password"' 
    raw: '"xcopy M:\isntaller.exe C:\installerlocation /Y"' 
    raw: '"net use M: /delete /y"' 

的文件确实在网络位置以及用户名密码存在是有效的。该任务不报告任何错误。但该文件永远不会被复制。

有谁知道我是否在做playbook语法错误?或者有更好的方法在安全的设置中跨网络位置获取文件?

P.S.我无法访问安全的服务器。尽管我知道它是一个Red Hat Linux服务器。

+1

除了明显的语法错误,这可能与https://stackoverflow.com/q/29222905/2947502 – techraf

回答

1

第三个raw覆盖了第一个和第二个,因为它们在同一个任务中。见YAML syntax overview

拆分到这3项独立的任务:

#WINDOWS# 
--- 
- hosts: windows 
    tasks: 

    - name: mount M 
    raw: '"net use M: "\\somemachinename\someLocation" /user:username password"' 

    - name: copy file 
    raw: '"xcopy M:\isntaller.exe C:\installerlocation /Y"' 

    - name: unmount M 
    raw: '"net use M: /delete /y"' 

此外,我不知道引号和双引号。你可能太多了。

0

尝试了很多组合后,终于为我工作了。看起来很拙劣,但可能对其他可能面临相同情况的人有帮助。

我在一个http位置添加了一个批处理文件,在这个位置可以找到它并在机器上执行。

REM @echo off 

set Source=%1% 
set Destination=%2% 

net use M: \\nwb-somemachinename /user:username password 
xcopy /F M:\%Source% %Destination% /Y 
net use M: /delete /y 

而且YML文件如下所示:

#WINDOWS# 
--- 
- hosts: windows 
    tasks: 

    - name: get batch file 
    raw: httptool.exe http://somelocation/ourbatchfile.bat 

    - name: run batch file 
    raw: c:\location\ourbatchfile.bat location_remote_machine\installer.exe c:\location