How to run a script in a remote Windows machine with Ansible

  ansible, powershell-remoting, script, windows

After tried many ways to run a script in a windows pc with Ansible, couldn’t make it work. Does someone know what can I do to succeed? Here’s what I have:

— Linux Ubuntu submodule running on Windows with Ansible installed

— Ansible host file with the content:

[uwp]
192.20.0.98
192.20.0.72

[uwp:vars]
ansible_user=user
ansible_password=**********
ansible_connection=winrm
ansible_port=5986
#ansible_winrm_scheme=https
ansible_winrm_server_cert_validation=ignore

— A playbook with the content:

- hosts: uwp
  tasks:
  - name: run script
    ansible.windows.win_powershell:
      script: |
        net use d: 192.20.10.42ProdFiles
        C:service-agent.jnlp

So if I run these both commands in the script section directly in the Windows pc they work fine. But when I run the command "ansible-playbook service-agents.yml" in the host machine where Ansible is installed it returns the output:

PLAY [uwp] ************************************************************************
TASK [Gathering Facts] ***********************************************************************************
ok: [192.20.0.98]
ok: [192.20.0.72]
TASK [run script] ************************************************************************************
changed: [192.20.0.98]
changed: [192.20.0.72]
PLAY RECAP ************************************************************************************
192.20.0.72                : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
192.20.0.98                : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
-----------------------------------------------------------------------------------------

As no error is reported it seems like it succeeded, however, nothing happen in the Windows remote machines. Hope someone can help. Thanks in advance!

Source: Windows Questions

LEAVE A COMMENT