DevOps Classroom Series – 12/Apr/2020

How to use custom roles

  • Now Create a playbook to execute the roles
  • Roles are generally referred from playbooks
    • Roles will be checked in
      1. relative to playbook filepath (./roles/<role-name>)
      2. in the home directory (~/.ansible/roles/<role-name>)
      3. in the ansible cfg directory (/etc/ansible/roles/<role-name>)
  • Refer here for the playbook scripts

Dynamic Inventory

  • Refer here for official docs
  • Dynamic inventory is a script written in any language which returs a json file in a particular structure when –hosts is called or when –list
  • Sample Structure of json
{
    'web': {
        'hosts': ['192.168.10.11', '192.168.10.12'],
        'vars': {
            'package_name': 'httpd',
            'ansible_ssh_user': 'ubuntu' 
        }
    },
    'db': {
        'hosts': ['192.168.11.11', '192.168.11.12'],
        'vars': {
            'username': 'admin',
            'password': 'admin@123'
        }
    }
}

Ansible Tower

  • Is an orchestration tool around ansible which can be used using

    • Web Pages
    • REST API
  • Ansible Tower is a paid tool

  • For the labsetup, we would use a Ansible Tower trail version

  • Ansible Tower Quick Start Guide Refer Here

  • Using Ansible Tower is all about configuring ansible-playbook executions from ui/periodic scheduled jobs and from rest api .

  • For Rest API refer here

  • Ansible Tower will maintain logs of every run done by ansible.

Enterprise Scenario

  • After writing Ansible Playbooks/Roles etc you need to run them from CI/CD Tools (like Jenkins/Azure DevOps) or from InfraProvisioning tools like Terraform/CloudFormation/ARM Templates

Exercise:

  1. Refer Here

  2. Write an Ansible Role to configure Tomcat 8 and then add playbooks to deploy gameoflife and openmrs into the Tomcat 8 Download Here

How to run the same ansible playbook for multiple environments

  • Lets assume you have role called as tomcat8
  • Lets assume you have a playbook called as useroledemo.yml
  • Now lets assume we have 4 environments
    • dev
    • QA
    • Automated-QA
    • UAT
  • Solution: For every environment create a separate inventory file
    • dev_hosts => ansible-playbook -i env\dev_hosts useroledemo.yaml
    • QA_hosts => ansible-playbook -i env\QA_hosts useroledemo.yaml
    • Automated-QA_hosts => ansible-playbook -i env\Automated-QA_hosts useroledemo.yaml
    • UAT_hosts=> ansible-playbook -i env\UAT_hosts useroledemo.yaml

Can i run Ansible Playbook on 100 nodes at same time

  • Ansible-PLaybook has option called as forking (-f), if you want to run ansible on 100 servers at same time use “`ansible-playbook -f 100 useroledemo.yml’
  • To run ansible-playbook on one server at a time
ansible-playbook -f 1 useroledemo.yml

What is synchronize module

  • To recursively copy file then use synchronize module Refer Here

Leave a Reply

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

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube