Control Node:
- CentOS 7
- Ansible 2.1
- pywinrm version from May 19th, 2016
Remote Node:
- Windows 7
- Powershell 3
I have to make a copy of directory on a share to another location on that
same share. The account I use for connecting does not have access to the
share so I am trying to use the rights of another account namely ADS-6999.
I wrote the following powershell script which works perfectly.
#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\
<https://urldefense.proofpoint.com/v2/url?u=http-3A__schemas.microsoft.com_powershell_2004_04-255C&d=CwMFaQ&c=IGDlg0lD0b-nebmJJ0Kp8A&r=ATO-uJXWOBdlXfHiWeQfW-8RNV-1NXeUTYIEq2ZNDg4&m=in7Buuqsxvy8HAxCzF8XAS-KloDKjjJbD4ngBha0PPI&s=VjSSrNkqwjFV6b0gKGfaXwJZSvO89D0V4tcmwkGii4A&e=>"><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
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/6d954f45-d042-47cd-be34-41644a7875a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.