DevOps | Scripts | Automation

Ansible

Setting up Windows Hosts for Ansible with CredSSP Authentication – II

In the first part of this article, it was explanation about how to configure Credssp for the windows hosts and how to validate it. You can check the first part from the below link.

https://theautomationcode.com/setting-up-windows-hosts-for-ansible-with-credssp-authentication-i/

Installing ansible packages for winrm.

If you have not already installed the pywinrm package which supports the working of ansible with the windows hosts, you can install it inside the Ansible server. Use the below command to install the python3 pip installer.

sudo apt-get install python3-pip -y 

Once done, install the pywinrm module.

sudo pip3 install pywinrm

To install the credssp module,

sudo pip3 install pywinrm[credssp]

Setting up the Ansible inventory file for the windows configuration.

if you are using the hosts file as an inventory file then edit the file with nano, vi or any other editor as shown below.

sudo nano /etc/ansible/hosts

Windows hosts configuration.

[winservers]
192.168.0.200
192.168.0.202

[winservers:vars]
ansible_user=example@ansibleuser
ansible_password=Password
ansible_connection=winrm
ansible_winrm_transport=credssp

ansible_winrm_server_cert_validation=ignore

Here, we have created group [winservers], you can use any name. Instead of the IP address, you can provide the hostname or the FQDN of the hosts if the DNS is properly configured and if its resolving. Inside the group variable [winservers:vars] we can provide the windows authentication settings.

To test the configuration, check the ping connectivity. We will use win_ping command.

ansible winservers -m win_ping

Cheers…!!!