Yeah, docs forthcoming for this stuff, but you need to specify a couple more things to make it work (since the global *nix defaults don’t make sense under Windows):
First and foremost, you never actually said you want to “become”, just “who” you want to become- you need to add “become: yes” (this is not Windows-specific). Then you need to tell us which become method to use (become_method: runas), as the default “sudo” isn’t implemented on Windows. You can set these at either the play or task level, as necessary, but “become: yes” is the key to actually making a task run as someone else- the rest is just “how”. See below for a sample.
Also, there’s a bug right now that’s preventing become from working under NTLM and Kerberos auth (fails with “Access is denied”), so you can only use it with Basic, CredSSP, and Certificate auth (hoping to nail this one down in the next few days).
Hope that helps…
-Matt
(ansible-dev) [mdavis@mdavis-t460p win2012r2-domain]$ cat become.yml
-
hosts: member1
gather_facts: no
become_method: runas
tasks:
-
name: as default user
win_shell: whoami
-
name: as administrator
become: yes
become_user: administrator
win_shell: whoami
(ansible-dev) [mdavis@mdavis-t460p win2012r2-domain]$ ansible-playbook -i hosts become.yml -vv -K
No config file found; using defaults
SUDO password:
PLAYBOOK: become.yml *******************************************************************************
1 plays in become.yml
PLAY [member1] *************************************************************************************
META: ran handlers
TASK [as default user] *****************************************************************************
task path: /home/mdavis/vm/win2012r2-domain/become.yml:5
changed: [member1] => {“changed”: true, “cmd”: “whoami”, “delta”: “0:00:00.156427”, “end”: “2017-03-02 11:29:12.986398”, “rc”: 0, “start”: “2017-03-02 11:29:12.829970”, “stderr”: “”, “stderr_lines”: , “stdout”: “ansible\testguy\r\n”, “stdout_lines”: [“ansible\testguy”]}
TASK [as administrator] ****************************************************************************
task path: /home/mdavis/vm/win2012r2-domain/become.yml:8
changed: [member1] => {“changed”: true, “cmd”: “whoami”, “delta”: “0:00:00.187422”, “end”: “2017-03-02 11:29:13.876657”, “rc”: 0, “start”: “2017-03-02 11:29:13.689234”, “stderr”: “”, “stderr_lines”: , “stdout”: “ansible\testguy\r\n”, “stdout_lines”: [“ansible\testguy”]}
META: ran handlers
META: ran handlers
PLAY RECAP *****************************************************************************************
member1 : ok=2 changed=2 unreachable=0 failed=0