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

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?

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

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

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

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

Thanks Jon.

I’ll give it a try and post back.

-Joe

Yes! That module works for me!

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

Thanks,
-Joe

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.

Nervermind. Figured out how to add custom_modules into roles:
http://docs.ansible.com/ansible/playbooks_roles.html

Thanks again.

-Joe