Ansible

Configure & Install Ansible Server

Install Ansible

Here are all the steps needed to install Ansible and configure the system to run your ansible scripts or playbooks

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible -y

Validate Ansible Version

$ ansible --version

Install Python

$ sudo apt install python3-pip

Validate Python Version

$ python3 --version

Enable WinRM for Windows Hosts

$ pip3 install "pywinrm>=0.3.0"

Windows Host Configuration

For Ansible to be able to connect to the Windows Host, host should be configured as well, I would say do this on the base image.

Following are the prerequisite for the windows host:

  1. .Net >=4.0 should be installed
    • Run the following command on the command prompt to validate .NET version
      • reg query “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP” (for .Net < 4.5)
      • reg query “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full” (for .Net > 4.5)
  2. Powershell >= 3.0 should be installed
    • Run the following command on the command prompt to validate Powershell version
      • powershell $PSVersionTable.psversion

WinRM service to be configured so that Ansible can connect to it, open the command prompt in admin mode and type the following

winrm enumerate winrm/config/Listener

Use the following script & run the following in PowerShell:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1"
$file = "$env:temp\ConfigureRemotingForAnsible.ps1"

(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)

powershell.exe -ExecutionPolicy ByPass -File $file
Ansible Documentation reference: https://docs.ansible.com/ansible/latest/user_guide/windows_setup.html#winrm-setup

Leave a Reply

Your email address will not be published. Required fields are marked *

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