<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">

Connecting Windows host to Ansible Engine

Surbhi Agarwal Feb 13, 2019

Windows Ansible Engine WinRM Powershell Linux Open Source

Ansible is a very useful tool. It is an open source IT configuration management, orchestration and deployment tool. It is better than Chef and Puppet as it is agentless. Which means, there is no need for you to install software, agent or additional firewall port on client systems or hosts. It is powerful and flexible and enables you to model even the most complex workflows and greatly helps to reduce the efforts. Ansible is efficient and simple as it uses simple syntax written in YAML called playbook with no extra software on your servers.
Now let's talk about how Ansible can be used with windows. Ansible is easy to use with Linux as there is SSH connection in it. But, for windows, you need a control machine where Ansible Engine needs to execute and run on Linux. Furthermore, Windows host through which you need to add Ansible Engine should be at least Windows 7 SP1 or latest.

Ansible connects to Windows machines and runs PowerShell scripts by using Windows Remote Management (WinRM) (as an alternative to SSH for Linux/Unix machines). For this, WinRM listener should be created and activated. The good news is, connecting to your Windows hosts can be done very easily and quickly using a script.
It requires PowerShell version 3.0 and .Net Framework 4.0 to be installed on a Windows host.

Now let's see the steps to set up WinRM

Windows Remote Management (WinRM) is a feature in Windows Vista which is perfect for using with Ansible Engine. It receives hardware data from WS-Management protocol implementations running on non-Windows operating systems. It is basically like a translator that allows different types of operating systems to work together. Now, let's have a look at the steps:

Step 1- You will get the script from the link provided below. Save this script with .ps1 in any folder of your Windows machine (host). Now, run this script on PowerShell as administrator.
https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemoting ForAnsible.ps1

power shell script

Step 2- Install pywinrm on your control machine (which is Ansible Engine) as this provides necessary dependencies for Ansible Engine to connect to WinRM installed on Windows host.

Command: pip install pywinrm

Step 3- Now, to connect Windows host to Ansible Engine, you need to make changes in /etc/ansible/hosts file.

[win4]
13.75.3.164 (machine IP)

[win4: vars]

ansible_user =Surbhi (machine user name)

ansible_password=hi@**********(machine password)

ansible_connection=winrm

ansible_port=5986

ansible_winrm_server_cert_validation=ignore

ansible engine

ansible host

Step 4- Test the connection if the Windows host is connected or not.

Command: ansible -m win_ping all

ansible m

Now, you can see you are successful in connecting Windows host to Ansible Engine.

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.