Publish Date: 2024-02-01
Ansible is known for its ability to automate many IT processes, which are usually performed manually, including provisioning, system configuration, and software deployment in a flexible, secure way.
while this is mostly true and widely implemented in Linux-based environments, it becomes challenging at first to manage a Windows environment, which we will address in our article today.
In order to run ansible over windows hosts we must have a contoler and a host, a controler is where ansible is installed and it should be linux, and a host where ansible will execute over and it could be both linux and windows, but in our case it is windows.
For Ansible controler to communicate with a Windows host and use Windows modules, the Windows host must meet these base requirements for connectivity:
As we said, The control machine should be a linux machine, and in our case it is an Ubuntu machine running ansible version 2.16:
the istallation and configuration of ansible is not addressed here, but you can install it quickly by running the following commands in your shell, if you have an ubuntu machine:Next we need to verify that PowerShell and .NET versions, already meet the requirements in the windows target host. and the most important part is to set up the WinRM.
There is a great PowerShell script that sets up both HTTP and HTTPS listeners with a self-signed certificate and enables the Basic authentication option on the service.
Execute the following lines to download and setup WinRM in your windows host:Execute the following commands to verify that winrm is configured correctly:
from the above output, we confirm that winrm is configured correctly .
next let's configure our control machine to execute a simple playbook.
This is the structure of our configuration files
add the entry of windows target hosts under the inventory file(hosts) :
under hosts_vars/windows10.yml file, add the following content:
let's first create a simple playbook to run against our windows 10 machine. the playbook test basic connectivity and ensure thar 7zip is installed :
now, let's execute our playbook:
Today we saw how configure a windows host to for ansible and a basic demo for running a playbook .