DevOps Classroom Series – 03/Jan/2021

Ansible Tower Setup

  • Ansible tower is a web application that helps in executing ansible playbooks and provides features such as
    • user management
    • reporting
  • Ansible tower can be installed on the machines with os from rhel Refer Here
  • Refer Here for installation steps
  • In this series lets create ansible tower using azure marketplace Preview Preview Preview Preview Preview
  • In the case of aws while launching ec2 instance select market place Preview Preview
  • Now launch the url https://<public-ip&gt; Preview Preview

Scenario: We have two environments

  • We have two environments
    • Dev
    • Test
  • In the dev environment we are asked to install java 11
    • command is sudo apt-get install openjdk-11-jdk
  • In the test environment we are asked to install java 8
    • command is sudo apt-get install openjdk-8-jdk
  • How can we do this by writing one playbook
  • Refer Here for the changeset Preview
  • Now lets try to run ansible playbook on dev environment Preview
  • Now lets try to run playbook on test environment Preview

Scenario: Sensitive Content

  • We have a variable file in ansible which has usernames and passwords stored in plain text
  • Displaying sensitive content in the form of plain text in ansible playbooks is not secure, so we need some way of encrypting this content and that is where Ansible vault comes into play
  • We can use ansible vault to create variables file with three options
    • prompt for password
    • password in text
    • password from script
  • Lets create a sensitive variable file using prompt Refer Here
ansible-vault create --vault-id @prompt vars/secretbyprompt.yaml
  • create a script file and then use it. Refer Here
ansible-vault create --vault-id ~/  vars/even_more_secure.yaml
  • Now lets apply encryption to existing file. Refer Here
ansible-vault encrypt --vault-id ~/ vars/sensitive.yaml
  • So now lets use vars/sensitive in ansible playbook

Setting up windows hosts for Ansible Control

  • Lets create a windows server Preview
  • To set up ansible to run with windows server, we need pywinrm module on the Ansible control server
  • Windows Server should have atleast
    • Powershell 3.0
    • .NET 4.0
  • In the windows server we would be configuring winrm listener
    • So login into windows server and launch powershell as admin
    • create an Self Certificate
    New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "$env:COMPUTERNAME" -FriendlyName "WinRM HTTPS Certificate" -NotAfter (Get-Date).AddYears(5)
    • store the thumbprint
    • With the generated certificate create a new winrm listener
    New-Item -Path WSMan:\localhost\Listener -Transport HTTPS -Address * -CertificateThumbPrint <your-thumbprint>
    • Now Lets add a firewall rule to allow https communication
     New-NetFirewallRule -DisplayName 'WinRM Mgmt' -Profile Domain,Private,Public -Direction Inbound -Action Allow -Protocol TCP -LocalPort 5986
     Set-Item -Path  "WSMan:\localhost\Service\Auth\Basic" -Value $true
    • Now install chocolatey on windows Refer Here

    • Now lets move to ansible control server

    • check if the winrm module is install in python Preview

    • install pip3 on control server

    sudo apt install python3-pip
    sudo pip3 install pywinrm

Parallelism in Ansible

  • Controlling ansible playbook execution strategies Refer Here
  • ansible by default can run parallely on 5 nodes which is referred as 5 forks.
  • To run the ansible playbooks on one node at a time, set the fork value to 1
  • In ansible we can set batch size for executing on nodes in the batches
- name: test playbook
  hosts: all
  serial: 2
    - name: test task
        msg: "this is test task"

Ansible Collections

  • In Ansible the major unit of work is modules. There are lots of community modules which are developed.
  • Earlier to make these modules available to the users it had to wait till the ansible release.
  • Since this process is not upto the mark ansible has introduced collections.
  • Collections is collection of
    • modules
    • roles
  • Ansible-Galaxy had undergone changes to include collections
  • lets review one ansible collection Preview Preview Preview Preview


  1. Create an ansible role to deploy openmrs Refer Here Preview
  2. Write an ansible playbook to install nop commerce on linux Refer Here
  3. Try this if possible Refer Here

Leave a Reply

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

About learningthoughtsadmin