How to make symbolic links in windows via Ansible ?

I am trying to make a lot symbolic links for my directories and files and manually i use mklink command to make them. Oddly enough, this command requires admin level privileges to create links.

How can i use mklink via ansible with admin privileges to create symbolic links ?

Obviously you will need to connect as an Administrator user.

You don’t mention which version of windows you are controlling but you may just need to temporarily disable UAC prompt for Administrator users.

On Server 2012 the setting for this is in

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System

ConsentPromptBehaviorAdmin
0

set it back to 2 to restore current default behaviour.

Hope this helps. I have not used mklink though.

Jon

Hi Jon,

I am using windows server 2012 R2. Disabling UAC doesn’t seem like a good idea, specially with my automation scripts on a regular basis. I am connecting via admin account obviously but that doesn’t seem to be enough for making a symlink. I will have to start a command shell using ‘Run as admin’.