Dark Mode
Image
  • Friday, 19 April 2024
DevOps-7: Configuration Management [Ansible]

DevOps-7: Configuration Management [Ansible]


DevOps-7: Configuration Management [Ansible] - Outline

7.1. Learning Objectives

Need to automate an infrastructure to manage all the running service form one place. It’s provided an access model control based upon the organization, teams and users.

Ansible:Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It can configuration of tools between service assets and configuration items.

YAML Scripting: YAML is a data serialization language that is often used for writing configuration files.

Terraform: Terraform is an open-source infrastructure as code software tool that enables you to safely and predictably create, change, and improve infrastructure.

 

7.2. Overview of Configuration Management

Configuration Management: It is a system engineering method that ensures a product’s characteristics remain consistent during its life cycle. It may cover non-IT assets and work products used to develop services. It provides a configuration model of the services, assets and infrastructure by recording the relationship between-

  • Service assets
  • configuration items
  • Controlled environments
  • Operational use

Any change in configuration can dramatically impact to (1) Performance (2) Security (3) Functionality

Configuration Management

It comprises any aspect that requires management is delivering an IT service.

  • Maintains information and relationship
  • Ensure information is maintained.

The configuration management application:

  • Identifies
  • Defines
  • Tracks

These records can be accessed from a central repository by other service manager application.

 

7.3. Roles of Configuration Management Tools

Configuration management tools allow modifications and deployments-

  • Scalable
  • Predictable
  • Faster
  • Repeatable

 

Advantages of using configuration management tools includes:

  • Increase the efficiency with a well-defined configuration process that improves visibility
  • Optimize cost by having detailed knowledge of all the IT elements.
  • Track requirements form specification to testing
  • Identify and control software versions.
  • Enhances system and process reliability by detection effects
  • Manage the information about the configuration item
  • Provides faster restoration of your service if a process failure occurs
  • Facilitate the conduct of functional configuration audits

 

Role of Configuration Management tools in DevOps and Ansible as an IT automation engine:

  • Cloud Provisioning
  • Configuration management
  • Application Deployment
  • Intra-service Orchestration

 

7.4. Popular Configuration Management Tools

There are several tools available for configuration management. Every tool has specific features to improve it for certain situations. The top 4 management tools for configuration are:

Configuration Management
SaltStack: Python-based open-source CM tool used to remotely manage configuration items.
Ansible: Python based CM tool, also considered as agentless CM tool.
Chef: Ruby based CM tool having integration with most of the cloud-based platforms.
Puppet: Ruby DSL-based CM tool used for managing software, system, and network configuration items.

 

7.5. Ansible Overview

Ansible Overview

It models the interaction between all your systems in your IT architecture.

  • Uses playbook to describe automation jobs which are written in YAML.
  • Designed for multi-tire deployment
  • Models IT infrastructure by interrelation all the systems.
  • Constructure for multi-level use from the ground up.

There are multiple ways to install Ansible,

  • yum
  • apt-get
  • git checkout
  • pip

The below command to check and find the dependencies of the packages,

$ sudo apt-get install -f

The below command is used to update package repositories and get latest package information,

$ sudo apt-get install software properties-common

Run commands to update the list of available software once again and install Ansible. It also pulls down Ansible PPA’s signing key and adds it to your system.

$ sudo apt-add-repository ppa:ansible/ansible

Download package information from all configured sources,

$ sudo apt-get update 
$ sudo apt-get install ansible

Now install ansible is completed.

 

7.6. Components of Ansible

These are the six components of Ansible,

  1. Modules: Ansible connects to nodes and sends scripts known as Ansible Modules. User can write their own modules. Most modules accept parameters that define the system’s desired state.
  2. Module utilities: Ansible stores function as module utilities when several modules use the same code, to reduce duplication and maintenance.
  3. Plugins: Ansible’s core functionality is augmented by plugins. Plugin execute on the control node within the /usr/bin/ansible method. Ansible comes with many useful plugins and can also be created.
  4. Inventory: It is a configuration file where user defines the host information. It is a text file that contains a list of servers or nodes that the user manages and configures.
  5. Playbooks: It is a blueprint of automation tasks, which are complex IT tasks with no human intervention. The playbooks are simply frameworks or per-written code. The script or instructions are written in YAML format.
  6. The Ansible search path: Modules, module utilities, plugins, playbook and tasks can all be stored in different location. Several files with similar or identical names in different location can be available on the Ansible control node. Search path decides which of these files Ansible can find and use.

 

7.7. YAML Scripting

YAML syntax is simpler for humans to read and write than other popular data formats like XML or JSON. Hence, Ansible uses it to express Ansible playbook.

  • Any YAML file begins with a list of items
  • Every item in the list is a key or value pair list, also known as a hash or dictionary
  • Every YAML file optionally start with –and ends with

Sample of YAML writing:

--- #Optional YAML Start Syntax
James:
        Name: james john
        Rollno: 34
        Div: B
        Sex: male
… #Optional YAML End Syntax

Basic rule to write YAML file,

  • YAML is case-sensitive
  • The files should have .yaml as the extension.
  • YAML doesn’t allow the use of tabs while crating YAML files; spaces are allowed instead.

 

7.8. Demo - Setup Apache Server with Ansible

To setup Apache Server with Ansible,

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

Ansible

$ sudo apt-get update 
$ sudo apt-get install ansible

Ansible

$ ssh-keygen -t rsa 
$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys
$ ssh localhost -p 42006

Ansible

$ sudo vi /etc/ansible/hosts

Ansible

$ ansible -m ping webservers 
$ sudo vi apache2.yaml

Ansible Ansible

$ anisble-playbook apache2.yaml

Ansible

$ ansible -m shell -a “service apache2 status” webservers

Ansible

 

7.9. Terraform Overview

Terraform is a popular service provider. It uses configuration files to specify the components required to run a single application or an entire datacenter. Terraform create an execution plan that explains how it will get to the target state and then executes it to build the infrastructure indicated.

Terraform can determine what has changed and develop incremental implementation plans.

Ansible

The key features of Terraform are:

  1. Infrastructure as Code: Uses a high-level configuration syntax. Allows a blueprint of your datacenter. Infrastructure can be shared and reused. The infrastructure Terraform can manage:

    The infrastructure Terraform can manage:

    • Low-level Components:
      • Compute instances
      • Storage
      • Networking
    • High-level Components:
      • Domain name system entries
      • SaaS features, etc.
  2. Execution Plans: It shows what Terraform will do when you can apply. The prevents unexpected manipulation of Terraform infrastructure.
  3. Resource Graph: It is a graph of all resource which parallelizes any non-dependent resource.
  4. Change Automation: Change sheets in Terraform provide information and a sequence of what changes will be made.

 

7.10. Demo - S3 Bucket Creation Using Terraform
$ pip install awscli 
$ sudo apt-get update
$ mkdir s3back
$ cd s3back
$ nano creds.tf

Ansible

creds.tf file is below,

Ansible Ansible

 

nano main.tf file is below,

Ansible

 

$ teffaform init

Ansible

$ terraform plan 
$ terraform apply

Ansible

 

Now open AWS panel and you can see your bucket,

 

Ansible

 

Comment / Reply From