Windows Server

How to configure a remote server (windows) to Support Ansible

configure remote server

Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of systems listed in the Ansible inventory file. This file can be found in this location /etc/ansible/hosts. You can specify a different inventory file using the -i <path> option on the command line Since Windows Server 2012.

Note: WinRM is enabled by default, but in most cases extra configuration is required to use WinRM with Ansible. Below are the steps to configure Windows hosts to be supported by Ansible.

Prerequisites
– Ensure you have the right version of PowerShell and .NET Framework.

Ansible WinRM Connectivity setup for Ansible
– The default ports for WinRM 2.x are HTTP port 5985 and HTTPS port 5986.

Method 1: This is my recommended method. The script can be found here https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
– Right-click on the content and copy the entire content into Notepad ++
The file type and extension (.ps1) must be appended as shown below
– Select the location to want to have the WinRM script saved.
– In my case, I have saved the file on the Desktop under the name ConfigureRemotingForAnsible.ps1

Windows

Next, Then run the PowerShell script. as shown below
– Ensure to launch PowerShell as an Administrator

Support Ansible

Navigate to the script location and run it. In this case, we have navigated to the Desktop location where we saved the script. Next, proceed and execute the WinRM script on the Windows host.

Ansible configuration

The output signifies that WinRM has successfully been installed.

This will set the basic settings. The ConfigureRemotingForAnsible.ps1 script is intended for training and development purposes only and should not be used in a production environment since it enables settings (like Basic authentication) that can be inherently insecure.

When this step is complete and the host inventory file is configured correctly as described in this link. Then you should be able to ping the remote host successfully as shown below.

Note: You may need to configure the Execution Policy in PowerShell in order to allow scripts to run. for more information, see the following links for more information https://techdirectarchive.com/2020/02/04/how-to-set-execution-policy/

See the following link for more information on setting up a Windows host.

Method 2: Use this method before if you will like to run the script locally without an internet connection.
Note: To run this command remotely, use the PSEXEC command to do this

psexec \\myserver -accepteula -nobanner -s -u DOMAIN\Administrator powershell -ExecutionPolicy Bypass -Command "iwr https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 -UseBasicParsing | iex"

There is also a free utility on enabling WinRM on Windows Machine locally and remotely https://bit.ly/2XLCYCn.

Also the the link below for more details.
https://docs.ansible.com/ansible/latest/user_guide/windows_winrm.html
https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html
https://bit.ly/3aeI3Wx
http://devopstechie.com/managing-windows-machines-with-ansible/

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x