I have been stuck with Ansible window module. I am just trying to ping windows machine.But i get 'connect timeout'
hosts
[windows]
192.168.1.13
group_vars/windows.yaml
ansible_user: raja
ansible_password: myPassword
ansible_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore
And While I run : ansible windows -vvv -i hosts -m win_ping
Using /etc/ansible/ansible.cfg as config file
<192.168.1.13> ESTABLISH WINRM CONNECTION FOR USER: raja on PORT 5986 TO 192.168.1.13
192.168.1.13 | UNREACHABLE! => {
"changed": false,
"msg": "ssl: HTTPSConnectionPool(host='192.168.1.13', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fcb12024a90>, 'Connection to 192.168.1.13 timed out. (connect timeout=30)'))",
"unreachable": true
}
However I can ping that windows machine using ping 192.168.1.13
Can Ansible run on Windows? No, Ansible can only manage Windows hosts. Ansible cannot run on a Windows host natively, though it can run under the Windows Subsystem for Linux (WSL).
Ansible communicates with hosts using the SSH protocol because it is available on all Linux, macOS, routers and switches by default. This means that Ansible can be used to manage systems that are not accessible from the machine where Ansible is running.
Ansible uses https by default unless ansible_port is 5985.
Connection plugins allow Ansible to connect to the target hosts so it can execute tasks on them. Ansible ships with many connection plugins, but only one can be used per host at a time. By default, Ansible ships with several connection plugins.
Log into WinServer1as Administrator, download ConfigureRemotingForAnsible.ps1 and run this PowerShell script without any parameters. Once this command has been run on the WinServer1, return to the Ansible1 Controller host. Test Connectivity to the Windows Server
To test connectivity to the Windows 10 host, run the command: # ansible winhost -m win_ping The output shows that we have indeed established a connection to the remote Windows 10 host from the Ansible Control node. This implies that we can now manage the remote Windows host using Ansible Playbooks.
Managing Linux hosts with both Ansible Tower/AWX is trivial, but Windows requires extra work. The biggest challenge is the connection, and on whether to use WinRM or SSH. The former is quite complex to configure, but there’s not a lot of information around how to set up the latter.
-debug:var=netstat This playbook does only one task, to connect to the servers in the Ansible inventory group “windows” and run the command netstat.exe -aand return the results. To run this playbook, run this command on Ansible1: ansible-playbook netstat_e.yml OK, not exciting, but it did run, just not very friendly.
You need to prep your windows machine for PowerShell remote management, otherwise ansible won't be able to connect to it. For most features to work you will need at least PowerShell 3.0 installed (which is only supported on Windows 7 SP1 or Windows Server 2008 SP1 and later versions), and also run this script, which will not only enable WinRM, but also install some necessary certificates for the connection to work.
Once you donwload the ConfigureRemotingForAnsible.ps1
file the following command from command line should do the job:
powershell.exe -File ConfigureRemotingForAnsible.ps1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With