Getting started with Ansible and Windows Automation Part 1




Introduction


In this blog I'll show you how to get WinRM up and running with basic authentication, In Part 2 of the blog, I'll show you how we get Ansible managing automation on Windows


For Ansible to communicate to a Windows host and use Windows modules, the Windows host must meet the following requirements:
  • Ansible can generally manage Windows versions under current and extended support from Microsoft,, Ansible can manage Desktop Operating System versions 7,8.1 and 10 as well as Server Operating Systems versions 2008, 2008R2, 2012, 2012R2, 2016 and 2019
  • Ansible requires PowerShe;ll 3.0 or newer and at least .NET 4.0 to be installed
  • A WinRM listener should be created and activated. This document covers the basic setup of WinRM 

Lab Setup

  • Ansible Server: Running on OEL 7.7
  • Windows host: Windows 10
  • Pure Storage FlashArray

Windows Prerequisite

  • Make sure WinRM on installed and working on Windows
  • Create an ansible user with administrator privileges

  • Add the ansible user to the Administrator group




  • Now, to allow basic authentication with WinRM, open up the CMD prompt in windows and type the following

  • This command allows unencrypted traffic

  • This enables basic authentication


Linux Prerequisite

NOTE: Ansible 2.9 is already installed on this machine


Install GCC and PYTHON


  • # yum install gcc python-devel
Install PIP if not already installed
  • # wget https://bootstrap.pypa.io/get-pip.py
  • # python get-pip.py
Install the PIP pywinrm package
  • # pip install pywinrm


Add the windows group and host to the ansible hosts file, the default location is in /etc/ansible/hosts however this can be changed to any directory by modifying the /etc/ansible/ansible.cfg file and editing the inventory location

In this example I have a group called win with a server called winsql, my control host is  ansible server



[win]
winsql
[control]
ansible-server ansible_connection=local

Test you can ping the winsql server

[oracle@ansible-server ansible]$ ping winsql

PING winsql (192.168.111.197) 56(84) bytes of data.
64 bytes from winsql (192.168.111.197): icmp_seq=1 ttl=128 time=0.548 ms
64 bytes from winsql (192.168.111.197): icmp_seq=2 ttl=128 time=0.519 ms
64 bytes from winsql (192.168.111.197): icmp_seq=3 ttl=128 time=0.533 ms
64 bytes from winsql (192.168.111.197): icmp_seq=4 ttl=128 time=0.587 ms


To make things easier to manage. I have created a winvar.yaml file to include all the variables required, rather than adding them into each playbook. 

---

ansible_user: ansible
ansible_password: P@ssw0rd
ansible_connection: winrm
ansible_winrm_transport: basic
ansible_winrm_port: 5985


Now if everything is working correctly we should be able to test pinging the windows server using ansible

[oracle@ansible-server ansible]$ ansible -m win_ping winsql

winsql | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

[oracle@ansible-server ansible]$






Comments

Popular posts from this blog

SQL Server container with Pure Storage Docker volumes

Oracle 19c Database clones using the Pure Storage Docker plugin

Cloning SQL Server Containers With Pure Storage Docker Volumes