Ansible, a powerful IT automation tool, allows you to manage both Linux and Windows systems efficiently. In this guide, we’ll walk you through setting up Ansible to manage a Windows Client running on AWS EC2. From creating the Windows VM to running your first Ansible playbook, we’ll cover all the necessary steps.
Key Features of Ansible
- Agentless: Ansible operates without requiring any software to be installed on the client machines it manages, unlike many other automation tools. It uses SSH for Unix-based systems and WinRM (Windows Remote Management) for Windows systems.
- Declarative Language: Ansible uses YAML to write playbooks, making it easy to read and write configurations. The declarative nature means you describe the desired state rather than how to achieve it.
- Modules: Ansible has a vast array of modules, which are essentially scripts that Ansible runs to perform tasks like installing packages, managing files, or configuring services.
- Idempotency: Ansible ensures that applying the same playbook multiple times will not alter the system’s state after the first application, provided the desired state is already achieved.
Pre-requisite:
- Ansible needs to be installed on the control node. This can be done using various package managers like pip, apt, or yum, depending on your operating system.
- Ansible requires Python 3.8 or later. Python should be installed on the control node (the machine from which Ansible commands are run).
- Ensure that the control node has network access to the managed nodes. Firewalls, security groups, or network policies should allow SSH traffic between these nodes.
- An AWS account to create and manage EC2 instances.
Step-by-Step Guide
Step 1: Create a Windows VM on AWS EC2
- Launch an EC2 Instance:
- Go to the AWS Management Console.
- Select “Launch Instance.
- Choose a Windows Server AMI.
- Select an instance type and configure instance details as needed.
- Add storage and configure the security group
- Review and launch the instance.
- Configure Security Group:
- Ensure the security group allows inbound RDP access (port 3389) from your IP address.
- Add an inbound rule for HTTPS (port 5986) to allow WinRM connections.



Step 2: Configure RDP and WinRM on the Windows VM
- Connect to the Windows VM via RDP:
- Extract the RDP password using the private key created during the instance setup.
- Use Remote Desktop Connection to connect to the instance using the public IP and the extracted password.
- Allow HTTPS WinRM Connections:
- Open “Windows Defender Firewall with Advanced Security.
- Create a new inbound rule allowing traffic on port 5986.



- Set Up WinRM:
- Open PowerShell as an administrator.
- Create a self-signed certificate:
New-SelfSignedCertificate -DnsName "<your-hostname>" -CertStoreLocation Cert:\LocalMachine\MyReplace hostname with vm’s public IPv4 DNS
You can find this in Instance Summary






- Note the certificate thumbprint (e.g., C3A6A14B6C36B726843EAE474AC5ECC5C0EFA17E).
- Create an HTTPS listener:
winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname="<your-hostname>"; CertificateThumbprint="<thumbprint>"}'



Step 3: Configure Ansible to Manage the Windows VM
- Install Ansible on Your Control Machine:
- Ensure you have Ansible installed.
- Create the Inventory File:



- Create an Ansible Playbook:
- Create a playbook file named windows-playbook.yaml with the following details
File: windows-playbook.yaml


Step 4: Run the Ansible Playbook
- Execute the Playbook:
- Run the following command to execute your playbook:






Conclusion
By following these steps, you have successfully set up Ansible to manage a Windows Client of AWS EC2. This setup allows you to leverage Ansible’s powerful automation capabilities to manage your Windows infrastructure efficiently. Whether you’re gathering system information or performing more complex tasks, Ansible simplifies and streamlines your administrative tasks.
















