#copies contents of a share directory to another share directory
$uncServer="\\10.1.123.123"
$uncSrc="\shareName$\dir1\dir2\dir3"
$uncDest="\shareName$\dir4\6999"
$userName="ADS-6999"
$password="p@ssw0rd"
$uncFullSrc = "$uncServer$uncSrc"
$uncFullDest = "$uncServer$uncDest"
net use $uncServer $password /USER:$userName
Copy-Item $uncFullSrc $uncFullDest -Recurse
net use $uncServer /delete
So I modified the script above to be called from ansible on the control node and saved it as "copyShare2Share.ps1 shown below:
#copies contents of a share directory to another share directory
param(
[string]$uncServer,
[string]$uncSrc,
[string]$uncDest,
[string]$userName,
[string]$password
)
$uncFullSrc = "$uncServer$uncSrc"
$uncFullDest = "$uncServer$uncDest"
net use $uncServer $password /USER:$userName
Copy-Item $uncFullSrc $uncFullDest -Recurse
net use $uncServer /delete
And I call the script from my ansible playbook as follows:
---
- name: deploy new software version
hosts: windows
vars:
currentDate: ""
machineId: "none"
source: "\\shareName$\\dir1\\dir2\\dir3"
destination: "\\shareName$\\dir4"
machineId: "6999"
uncServer: "\\\\10.1.123.123" - name: BACKUP FILES
tasks:
- name: BACKUP USER FILES
script: copyShare2Share.ps1 {{uncServer}} {{source}} "{{destination}}\{{machineId}}" "ADS-6999" "adsads"
Here is what I get for output:
<ADS-6999> EXEC & 'C:\Users\ansibleAdmin.ADS-6999\AppData\Local\Temp\ansible-tmp-1464986197.84-138031458928067\copyShare2Share.ps1' \\10.1.123.123 \shareName$\dir1\dir2\dir3\ "\shareName$\dir4\\6999" "ADS-6999" "p@ssw0rd"
<ADS-6999>
WINRM EXEC 'PowerShell' ['-NoProfile', '-NonInteractive',
'-ExecutionPolicy', 'Unrestricted', '-EncodedCommand', '
"stderr": "The user
context supplied is invalid.\r\n\r\nMore help is available by typing NET
HELPMSG 3775.\r\n\r\n#< CLIXML\r\nThe network connection could not
be found.\r\n\r\nMore help is available by typing NET HELPMSG
2250.\r\n\r\n<Objs Version=\"1.1.0.1\" xmlns=\"http://schemas.microsoft.com/powershell/2004/04\"><S
S=\"Error\">Copy-Item : Access is
denied_x000D__x000A_</S><S S=\"Error\">At
C:\\Users\\ansibleAdmin.ADS-6999\\AppData\\Local\\Temp\\ansible-tmp-1464986197.84-_x000D__x000A_</S><S S=\"Error\">138031458928067\\copyShare2Share.ps1:12
char:1_x000D__x000A_</S><S S=\"Error\">+ Copy-Item
$uncFullSrc $uncFullDest -Recurse_x000D__x000A_</S><S
S=\"Error\">+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~_x000D__x000A_</S><S S=\"Error\"> + CategoryInfo : PermissionDenied:
PLAY RECAP *********************************************************************
ADS-6999 : ok=4 changed=2 unreachable=0 failed=0