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.
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.
126.96.36.199 (machine IP)
ansible_user =Surbhi (machine user name)
Step 4- Test the connection if the Windows host is connected or not.
Command: ansible -m win_ping all
Now, you can see you are successful in connecting Windows host to Ansible Engine.