Remote Windows batch script says completed successful, but did not work

739 views
Skip to first unread message

Joe Levis

unread,
Jan 22, 2016, 1:02:17 PM1/22/16
to Ansible Project
I'm running Ansible 2.0.0.2 on a Ubuntu 14.04 Control Machine. I'm using the script module in my Playbook to run a batch file, which executes a PowerShell script to create a Windows share (Windows Server 2012 R2). The Playbook completes successfully:

ok=3    changed=1    unreachable=0    failed=0


However, the share is not created.


I confirmed it works if I run the same batch file manually on the Windows server.


Here's my Playbook:

- name: Create shares

  script: files/ui/create-shares.bat

  tags: create-shares


Here's the batch script:

@ECHO OFF

SET PowerShellScriptPath=C:\create-shares.ps1

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs}";


Here's the PowerShell script:

New-SmbShare -Name test -Path C:\test -FullAccess domain\user


Any ideas?

J Hawkesworth

unread,
Jan 22, 2016, 1:40:26 PM1/22/16
to Ansible Project
My guess would be you need to run as a privileged user, such as Administrator.

There is a PR for a win_share module which sounds like just what you are after though.

I will dig out the link.

Jon

J Hawkesworth

unread,
Jan 22, 2016, 1:40:26 PM1/22/16
to Ansible Project

Joe Levis

unread,
Jan 22, 2016, 1:43:41 PM1/22/16
to Ansible Project
Hi Jon,

Thanks for the quick reply.

I'm authenticating to the Windows server using kerberos and the user is an Administrator on the server.

-Joe

J Hawkesworth

unread,
Jan 22, 2016, 1:45:33 PM1/22/16
to Ansible Project
It's here

https://github.com/ansible/ansible-modules-extras/pull/1213

Would be great if you could test it as it would get it one step closer to being included in Ansible.

Jon

Joe Levis

unread,
Jan 22, 2016, 2:12:30 PM1/22/16
to Ansible Project
Thanks Jon.

I'll give it a try and post back.

-Joe

Joe Levis

unread,
Jan 22, 2016, 3:02:41 PM1/22/16
to Ansible Project
Yes! That module works for me!

I've approved the Pull Request in GitHub as well.


Thanks,
-Joe

Joe Levis

unread,
Jan 22, 2016, 5:44:48 PM1/22/16
to Ansible Project
It looks like the PR for the win_share module is ready to be merged - do you know when that would actually be merged into the devel branch?

Also, do you know where my modules are located if I've installed Ansible using the apt-get repo? The ansible.cfg on my Ubuntu machine has a commented-out library location:

$ cat /etc/ansible/ansible.cfg | grep library

#library        = /usr/share/my_modules/


And /usr/share/my_modules is empty.

Joe Levis

unread,
Jan 22, 2016, 6:15:33 PM1/22/16
to Ansible Project
Nervermind. Figured out how to add custom_modules into roles:

Thanks again.

-Joe
Reply all
Reply to author
Forward
0 new messages