2017-07-03 31 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