How to run interactive .exe on Windows with Ansible

Starting with version 1.7, the orchestration tool Ansible has a support for managing Windows machines. What the documentation does not provide is a guide on how to run interactive applications properly.

The problem

If you try running any interactive app using the raw or win_command modules, such as in the following example:

the execution will hang at the Run Windows Calculator step, with no application running. What actually happens is that the application starts in the background in a different session, without displaying the UI to you.

Solution

What you need to do is to get your app running in the session you are observing. If there is only one user logged in, it will be session number 1. There are several hackish, long and complicated ways of doing that. And there is one simple one. You can run the app through a program called PsExec, which will run it in correct session:

  1. Download the PsTools package that contains the PsExec.exe program.
  2. Extract PsExec.exe to some folder <WORKING_FOLDER>.
  3. Use the following playbook (replace <WORKING_FOLDER> with the actual location):
The -i 1 option will cause running the app in session 1. The -s option will run the app as system. This is not required for running a Windows Calculator. But it will be useful if you'll ever need to run an installer or something similar. All the command line options of PsExec are described here.

Finally, run the playbook:

Notes

  • To automate interaction with Windows apps, have a look at AutoIt.
  • You may need to turn off UAC. Since I discourage doing so, I will not provide a link on how to do that.
Související články / Related posts:

Zanechte komentář / Leave a comment

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