[Ansible] - PsExec model

Hi,

I’m trying to use this new module (PsExec without WinRM connection type) from Ansible 2.6 and going through the documentation I don’t see any example on how I should configure the connection to use PSEXEC and since I don’t have such configuration the playbook tries to connect on port 445 but using SSH, I also tried connection type local but didn’t work.

Can anyone give me a hand to clarify this?

https://docs.ansible.com/ansible/devel/modules/psexec_module.html

https://github.com/jborean93/pypsexec

Best Regards

The psexec module is a module not a connection plugin so the inventory setup doesn’t really affect how it actually runs. What happens when you specify a task with the psexec module is that the Python code is run on the host specified and it connects to the Windows host that is specified by the module options. If we use the first example in the psexec documetation


- name: run a cmd.exe command
  psexec:
    hostname: server
    connection_username: username
    connection_password: password
    executable: cmd.exe
    arguments: /c echo Hello World

We can see that the client side that runs the psexec module will connect to ‘server’ using the credentials ‘username’/‘password’ and execute ‘cmd.exe /c echo Hello World’. Where this code is run is dependent on what the current playbook host is configured like. In most cases people will probably run this module on the localhost (Ansible controller) and this can be done by specifying ‘hosts: localhost’ on the playbook or by using ‘delegate_to: localhost’ like below.


- name: run a cmd.exe command
  psexec:
    hostname: server
    connection_username: username
    connection_password: password
    executable: cmd.exe
    arguments: /c echo Hello World
  delegate_to: localhost

Delegate to is useful if you are running a task targeting towards one host but you need to run this individual task on a different host. Hopefully this helps to explain it a bit more.

Thanks

Jordan

Thanks Jordan for your answer but I still don’t understand.

So the main purpose is not to orchestrate remote machines via this module?

Thanks
Mahatma

It’s purpose is really to allow you to enable WinRM on a remote Windows host so you can then use the winrm connection plugin with the Windows modules. You can technically use it to run any other command in an adhoc fashion but this would get tiresome pretty quickly.

Thanks

Jordan

i had the same question as posted in the thread
glad to see the answer :slight_smile: thank you Jordan