Manage Windows Machines with Ansible – Install and Configure Ansible – Part 3

In this third blog post in the manage Windows machines with Ansible series, I will show you how to install and configure Ansible and add a Windows machine.

At the end of this post, you will be able to connect to Active Directory from Ansible, authenticate to a Windows host and test the everything is working.

In the series

NTLM

To get Ansible communicating with Active Directory, we will configure NTLM using the Ansible account we have created in the first part.

Install Ansible

Installing Ansible is not complicated and doesn’t take long to complete.

I will the following two cmdlets to install Ansible.

Apt update
apt install ansible

Ansible configuration location

Once Ansible is up and running, you will find the configuration files in the following location:

/etc/ansible

Ansible Files

By default, the Ansible directory comes with the following two files:

Hosts – This is where we add our Windows or Linux hosts.

Ansible .cfg – This is the main Ansible configuration file; in most cases, there is no need to modify this file.

Add host

I will start with adding my Windows machine to the hosts’ file using the nano editor however you can use any editor you like.

nano hosts

File

Below, I will add my first Windows machine to Ansible, as shown below.

My windows machines, Win-host-01 belongs to the Windows machine groups.

In the third like of the configuration, I am adding the details of the Active Directory user account and the NTLM configuration.

[windows]

win-host-01
windows:vars]
ansible_user=ansible
ansible_password=password
ansible_connection=winrm
ansible_winrm_transport=ntlm
ansible_winrm_server_cert_validation=ignore

After adding the configuration to the host file, I will save the file and go to the configuration step.

Test

To test if everything is working and Ansible can connect, authenticate and ping my Windows machine, I will run the following command.

If all goes well, you will see the SUCCESS message, as shown in the figure below.

ansible windows -I hosts -m win_ping

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.