How to run interactive .exe on Windows with Ansible

Star­ting with ver­si­on 1.7, the orchestrati­on tool Ansi­ble has a sup­port for mana­ging Win­dows machi­nes. What the docu­men­tati­on does not pro­vi­de is a gui­de on how to run inter­acti­ve appli­cati­ons pro­per­ly.

The problem

If you try run­ning any inter­acti­ve app using the raw or win_command modu­les, such as in the following exam­ple:

the execu­ti­on will hang at the Run Win­dows Cal­cu­la­tor step, with no appli­cati­on run­ning. What actu­ally hap­pens is that the appli­cati­on starts in the bac­kground in a dif­fe­rent sessi­on, without dis­pla­y­ing the UI to you.

Solution

What you need to do is to get your app run­ning in the sessi­on you are obser­ving. If the­re is only one user logged in, it will be sessi­on num­ber 1. The­re are seve­ral hac­kish, long and com­pli­ca­ted ways of doing that. And the­re is one sim­ple one. You can run the app throu­gh a pro­gram called PsExec, which will run it in correct sessi­on:

  1. Down­lo­ad the PsTools pac­kage that con­ta­ins the PsExec.exe pro­gram.
  2. Extract PsExec.exe to some fol­der <WORKING_FOLDER>.
  3. Use the following pla­y­book (repla­ce <WORKING_FOLDER> with the actu­al locati­on):
The -i 1 opti­on will cause run­ning the app in sessi­on 1. The -s opti­on will run the app as sys­tem. This is not requi­red for run­ning a Win­dows Cal­cu­la­tor. But it will be use­ful if you’ll ever need to run an installer or some­thing simi­lar. All the com­mand line opti­ons of PsExec are descri­bed here.

Finally, run the pla­y­book:

Notes

  • To auto­ma­te inter­acti­on with Win­dows apps, have a look at Auto­It.
  • You may need to turn off UAC. Sin­ce I dis­cou­rage doing so, I will not pro­vi­de a link on how to do that.
Sou­vi­se­jí­cí člán­ky / Rela­ted posts:

2 Komentářů / Comments

  1. Hmm.. Try­ing your exam­ple and it doesnt seem to be wor­king. It han­gs on run exe task. Here is my pla­y­book


    – name: cre­a­te file
    hosts: win­dows
    tasks:

    – name: run exe
    win_command: C:\Users\Administrator\intelex\PsExec.exe -accep­te­u­la -noban­ner -i 1 -s calc.exe
    regis­ter: out­put

    The pla­y­book also errors on syn­tax error when run with quo­tes in your exam­ple.

Zanechte komentář / Leave a comment

Your email address will not be published. Required fields are marked *