In this blog I will be manage a windows box remotely via awx ansible – I will setup the windows box to be managed, I will setup AWX so we can manage windows boxes and then create and run a playbook.
- On your managed windows box run the following
Set-ExecutionPolicy RemoteSigned -Force
Enable-PSRemoting -Force
New-NetFirewallRule -Name "WinRM-HTTP" -DisplayName "WinRM over HTTP" -Protocol TCP -LocalPort 5985 -Action Allow

2. create your inventory file with the following information
Variables yml
ansible_connection: winrm
#ansible_winrm_transport: basic
ansible_winrm_transport: ntlm
ansible_winrm_scheme: http
ansible_port: 5985
ansible_winrm_server_cert_validation: ignore
hosts – have your ip of your windows box


3. Create Credentials as machine type with your domain creds

4. Create your template job

5. example playbook output ipconfig and stop service
---
- name: Run commands on Windows host
hosts: 192.168.1.11
gather_facts: false
tasks:
- name: Execute a command using win_command
ansible.windows.win_command:
cmd: "ipconfig /all"
register: ipconfig_output
- name: Print the output of ipconfig
debug:
var: ipconfig_output.stdout_lines
- name: Stop Windows Update service
ansible.windows.win_shell: |
Stop-Service -Name "wuauserv" -Force
register: processes_output
- name: Print the output of net stop
debug:
var: processes_output.stdout_lines
Difference between win_command and win_shell is
Use win_command for simple commands or when shell features are not needed and security is a concern. Use win_shell when you need to leverage shell features, execute multi-line commands, or when dealing with complex scripts.
Output
