To follow the steps below, you need to have Python 3.x and Ansible installed on both the systems. You can follow the below articles if you need help. How to Install and Configure Ansible on Ubuntu? How to install Ansible on Windows? Below are the details of both the servers I am using:
Ansible Controller – 192.168.0.108 Windows Server – 192.168.0.102
Step 1: Create Ansible Windows User
Create a new user for the Ansible windows connection setup.
Open Computer Management on your Windows system and go to Local Users and Groups. Right-click on Users and create a new user. Select Password never expires checkbox and click on create.
Now among the available groups, right-click on the Administrators group and click on properties. Click on Add and enter ansible in object names. Click on the check names option and then Ok.
Now, an ansible user on a windows machine is ready.
Step 2: Setup Libraries and WinRM
Go to your ansible controller machine, update it, and install the libraries mentioned below. WinRM stands for windows remote management. It allows you to perform management tasks on remote windows systems. We will install python3-winrm, a python client that is used to make a connection to the windows system.
Step 3: Update the Ansible Inventory file
Now, I will edit the ansible hosts file with the windows system IP address. So now ansible will know which windows system it needs to connect.
Step 4: Update the Ansible Group Variables
Create a directory for putting variables need to connect to the windows system. Create a file win.yaml and put the user details you created in the 1st step and few more variables required to connect to the windows system.
Step 5: Configure Windows Servers to Manage
Open your windows power shell and upgrade it. You need to have Powershell 3.0 and .NET Framework 4.0 present on the windows machine. To configure WinRM on a Windows system with ansible, a remote configuration script has been provided by ansible. Run the script in the PowerShell. Set winrm to allow HTTP traffic. Set the authentication to basic in wirm.
Step 6: Test Connectivity to the Windows Server
Now all the steps on the machine are done. Go to ansible controller machine and ping the windows server machine using win_ping ansible module. The success message shows that the connection has been established. Now, the windows system is ready to be administered remotely from the Ansible running on Ubuntu.