Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ansible, How to connect to windows host?

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

like image 519
rajagopalx Avatar asked Jul 08 '16 05:07

rajagopalx


People also ask

Can Ansible manage Windows hosts?

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).

How does Ansible connect to host?

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.

What port does Ansible use for Windows?

Ansible uses https by default unless ansible_port is 5985.

How does Ansible connect to target host?

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.

How to configure Ansible to connect to a Windows Server?

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

How to manage remote Windows 10 hosts with Ansible playbooks?

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.

Can I use Ansible Tower/AWX with manage Linux hosts?

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.

How do I run netstat on Ansible 1?

-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.


1 Answers

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

like image 83
SztupY Avatar answered Oct 04 '22 02:10

SztupY