# win\_command with become still doesn't seem to work

**URL:** <https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677>\
**Category:** Ansible Developer\
**Tags:** windows\
**Created:** [February 14, 2019, 1:25am UTC](https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677 "2019-02-14T01:25:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_V](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_V](https://forum.ansible.com/u/Mike_V)\
**Post date:** [February 14, 2019, 1:25am UTC](https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677/1 "2019-02-14T01:25:26Z")

</div>

Hi,

I’m trying to remotely install visual studios. I’ve staged the installation file locally and able install if logged in with local admin account.

Failed attempt #1  
win\_command: c:\stage\vs\_Enterprise.exe --add Microsoft.VisualStudio.Workload.NativeDesktop --quiet  
become: yes  
become\_method: runas  
become\_user: \user  
vars:  
ansible\_become: yes  
ansible\_become\_method: runas  
ansible\_become\_user: \user  
ansible\_become\_pass:

Failed attempt #2  
on another remote computer, i use the invoke-command and pass the same credentials. invoke-command uses WinRM.

Successful attempt #1  
Like I mentioned, I’m able to install by locally logging in.

Successful attempt #2  
on another remote computer, i use enter-psession

On both failed attempts, the visual studio creates a folder in the %temp% drive and then deletes it and the bootstrapper and setup process terminates. Visual studio will kickoff a bootstrap process, then another vs\_setup\_process, and then a bunch of windows installer process. I don’t think these processes are getting the right permissions?

Any ideas? Am I using “become” right? Sorry, first time using ansible.

P.S. I really want to avoid psexec and installing an agent just to do an install

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [February 14, 2019, 4:50am UTC](https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677/2 "2019-02-14T04:50:38Z")

</div>

Just a few things to note, you don’t need to set the task directory become, become\_method, become\_user if you have set the vars as well. Variable \> than task directives when it comes to precedence.

If the initial exe is then starting up another executable and exits immediately it makes sense that it wuld come back ok but then kill the WinRM session and subsequently all child processes, like the newly spawned installer.

I would try and add ‘async: 600’ to the task to see if that works for you. Async slightly changes the type of session the module is run in and it may be enough to get things working for you but there’s no guarantees.

If I get some time I might try this out but I can’t do it right now.

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [February 14, 2019, 11:26am UTC](https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677/3 "2019-02-14T11:26:45Z")

</div>

I found some time to play around with this a bit more. It turns out the initial installer spawns multiple processes and doesn’t actually wait until it is finished. This causes the parent WinRM process to close it’s shell which has the side affect of killing any children it spawns.

It’s weird behaviour from the installer as it should be waiting until all the installed processes have finish before finishing but this isn’t the case. The reason why it works when you run locally or through ‘Enter-PSSession’ is because those sessions are persistent, whereas Ansible and ‘Invoke-Command’ will close that session as soon as it’s command is finished.

Luckily using async will allow you to escape this behaviour, using the following playbook you can install VS and wait until the installer has actually completed. It uses async on the first task so that the spawned installer is not killed when WinRM exits and then waits until it is complete in the 2nd task. Become isn’t needed for this task, you just need to escape the WinRM job boundary which is what async is for.

`

---

<div class="post-metadata">

**Author:** ![Mike\_V](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_V](https://forum.ansible.com/u/Mike_V)\
**Post date:** [February 14, 2019, 5:18pm UTC](https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677/4 "2019-02-14T17:18:00Z")

</div>

Thank you Jordan! I just tried the suggestion and it works great! I agree, the installer is terrible to begin with. I initially wanted to do a chocolatey package but it was overwhelmingly even more complex too learn for this type of installer. I really appreciate your help and test

---

<div class="post-metadata">

**Author:** ![Christopher\_Perrin](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Christopher\_Perrin](https://forum.ansible.com/u/Christopher_Perrin)\
**Post date:** [February 15, 2019, 3:15pm UTC](https://forum.ansible.com/t/win-command-with-become-still-doesnt-seem-to-work/29677/5 "2019-02-15T15:15:30Z")

</div>

Maybe you could try the win\_chocolatey. It has a VS2017 package

`

- name: install VS2017  
win\_chocolatey:  
name: `visualstudio2017enterprise`  
```package_params: “``–add Microsoft.VisualStudio.`Workload.NativeDesktop`”` `state: present`

`

I have not tested this. But maybe this is more stable than the other solution.
