Quantcast
Channel: Cloud Training Program
Viewing all articles
Browse latest Browse all 1891

Ansible for Beginners Day1 Live Session Review and Q/A

$
0
0

This blog post covers a brief overview of the topics covered and some common questions asked during Day 1 Live Interactive training on Ansible for Beginners.

During our Day 1 Live Session, we covered Introduction to Ansible, Ansible Inventory & Ad hoc commands Basics of Ansible Playbook and performed Lab1, Lab2, Lab3, Lab4, Lab5 from 9 Hands-On Labs

There are 7 modules covering 30+ lessons & 9 extensive step-by-step Hands-on labs which are vital to becoming an Automation with Ansible certified.

  • Module 1: Introduction to Ansible
  • Module 2Ansible Inventory & Ad hoc commands
  • Module 3: Ansible Playbook, Modules & Privilege Escalation
  • Module 4: Ansible Variables
  • Module 5: Conditional Execution & Loops
  • Module 6: Managing files & roles
  • Module 7: Advanced Topics & Ansible Tower

Automation

In simple words, Automation has become known more as using machines to reduce work performed by humans. In other words, it frees up time and increases efficiency.

Ansible Automation Platform’s human-readable YAML automation language makes it possible for users across an organization to share, vet, and manage automation content.

Collaborate across teams and get up and running quickly with searchable collections of pre-composed roles and modules so any ansible Automation Platform’s human-readable YAML automation language makes it possible for users across an organization to share, vet, and manage automation content.

Why Automation?

Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.

  • Reduce inefficiencies
  • Lower production
  • Reduce complexity
  • Eliminate gaps in security.

Automation

Ansible

Ansible is an open-source automation tool with a simple automation language that can perfectly describe IT application environments in Ansible Playbooks.

Ansible provides reliability, consistency, and scalability to your IT infrastructure. You can automate configurations of databases, storage, networks, firewalls using Ansible. It makes sure that all the necessary packages and all other software are consistent on the server to run the application.

Also check: Ansible for Beginners

Q1. Explain the Ansible Architecture?

Ans. The Ansible Automation Engine consists of:Architecture

  • Inventories: Ansible reads information about the machines you manage from the inventory. Inventory is listed in the file which contains IP addresses, databases, and servers. Ansible then takes action via a transport – SSH for UNIX, Linux, or Networking devices and WinRM for Windows system.
  • APIs: APIs in Ansible are used as transport for Cloud services, public or private.
  • Modules: Modules are executed directly on remote hosts through playbooks. The modules can control system resources, like services, packages, or files (anything really), or execute system commands.
  • Plugins: Plugins allows to execution of Ansible tasks as a job build step. Plugins are pieces of code that augment Ansible’s core functionality. Ansible ships with several handy plugins, and you can easily write your own.
  • Networking: Ansible can also be used to automate different networks. Ansible uses the same simple, powerful, and agentless automation framework IT operations and development are already using. It uses a data model (a playbook or role) that is separate from the Ansible automation engine that easily spans different network hardware.
  • Hosts: The hosts in the Ansible architecture are just node systems that are getting automated by Ansible. It can be any kind of machine – Windows, Linux, RedHat, etc.
  • Playbooks: Playbooks are simple files written in YAML format which describes the tasks to be executed by Ansible. Playbooks can declare configurations, but they can also orchestrate any manual ordered process steps, even if it contains jump statements. They can launch tasks synchronously or asynchronously.
  • CMDB: It is a repository that acts as a data warehouse for IT installations. It holds data relating to a collection of IT assets (commonly referred to as configuration items (CI)), as well as describes relationships between such assets.
  • Public/Private Cloud: It is a network of remote servers hosted on the Internet to store, manage, and process data, rather than a local server. You can launch your resources and instances on the cloud and connect to your servers.

Q2. What are the important components of Ansible?

Ans. There are mainly two important components of ansible:

1. Controller nodes: The main machine where Ansible is installed is responsible for running the provisioning on the servers you are managing. You need at least Python 2.6 or a later version installed.

2. Managed nodes or servers: The network devices (and/or servers) you manage with Ansible. Managed nodes are also sometimes called “hosts”. Ansible is not installed on managed nodes. You need at least Python 2.6 or a later version installed.

Q3. What are the advantages of using Ansible?

Ans. Simple: Ansible uses a simple syntax written in YAML called playbooks. YAML is a human-readable data serialization language.

Agentless: Ansible is completely agentless. There are no agents/software or additional firewall ports that you need to install on the client systems or hosts which you want to automate.

Powerful & Flexible: Ansible has powerful features that can enable you to model even the most complex IT workflows.

Efficient: Because you don’t need to install any extra software, there’s more room for application resources on your server.

Q4. What are the features of using Ansible?

Ans. The features of using ansible are:

Human Readable: Ansible is using the popular YAML format for playbooks and no scripting knowledge is required.

Ansible_Features

Q5. Where should I use Ansible?

Ans. We use ansible in the following ways:

  • Provisioning: Provisioning is creating new infrastructure. Ansible allows for application management, deployment, orchestration, and configuration management.
  • Continuous Delivery: Ansible provides a simpler way to automatically deploy applications. All required services for a deployment can be configured from a single system. Continuous Integration (CI) tool can be used to run Ansible playbook which can be used to test and automatically deploy the application to production if tests are passed.
  • Application Deployment: Ansible provides a simpler way to deploy applications across the infrastructure. Deployment of multi-tier applications can be simplified and the infrastructure can be easily changed over time.
  • Configuration management: Centralizing configuration file management and deployment is a common use case for Ansible, and it’s how many power users are first introduced to the Ansible automation platform.
  • Security automation: When you define your security policy in Ansible, scanning, and remediation of site-wide security policy can be integrated into other automated processes and instead of being an afterthought, it’ll be integral in everything that is deployed.
  • Orchestration: Configurations alone don’t define your environment. You need to define how multiple configurations interact and ensure the disparate pieces can be managed as a whole. Out of complexity and chaos, Ansible brings order.

use Ansible

> Ansible Case Study-

  • A Real-Life Usage by NASA

Ansible Configuration

Ansible supports several sources for configuring its behavior, including an ini file named ansible.cfg, environment variables, command-line options, playbook keywords, and variables.

The ansible-config utility allows users to see all the configuration settings available, their defaults, how to set them, and where their current value comes from. See ansible-config for more information.

The configuration file:

You can store ansible.cfg at below locations and see the preference order(top item has the most priority):

  • $ANSIBLE_CONFIG – Enviroment variable
  • ./ansible.cfg – cfg file in current directory
  • ~/.ansible.cfg – home directory
  • /etc/ansible/ansible.cfg – default cfg

Ansible Configuration:

[Defaults]
#inventory file location
inventory = ./inventory

#which user credential ansible has to use to connect to host
remote_user = someuser

#whether it should ask for "someone password"
ask_pass = false

[privilege_escalation]
#enable privilege escalation
become = true

#set to use sudo for privilege escalation
become_method = sudo

#privilege escalation user
become_user = root

#enable prompting for the privilege escalation password
become_ask_pass = true

Inventory

The Ansible inventory file defines the hosts and groups of hosts upon which commands, modules, and tasks in a playbook operate. The file can be in one of many formats depending on your Ansible environment and plugins. Common formats include INI and YAML. The default location for the inventory file is /etc/ansible/hosts.

Static and Dynamic Host Inventories-

  • Inventories are simply the manage nodes or target devices Ansible needs to manage.
  • Store inventory as static fields or dynamic inventory scripts.
  • The default location can be configured in ansible. cfg or pass while executing the automation playbook.

Q6. What is Static and Dynamic Inventory with examples?

Ans. Static Inventory: In Ansible, a static inventory file is a plain text file that contains a list of managed hosts declared under a host group using either hostnames or IP addresses.

[webservers]
173.82.115.165
[database_servers]
173.82.220.239
[datacenter:children]
webservers
database_servers

Dynamic Inventory: A dynamic inventory is a script written in Python, PHP, or any other programming language.

{
  "webservers": {
    "hosts": [
      "webserver1.example.com",
      "webserver2.example.com"
    ],
    "vars": {}
  },
  "database_servers": {
    "hosts": [
      "mysql_db1",
      "mysql_db2"
    ],
    "vars": {}
  },
  "_meta": {
    "hostvars": {
      "mysql_db2": {},
      "webserver2.example.com": {},
      "webserver1.example.com": {}, 
      "mysql_db1": {}
    }
  }
}

Ad-hoc Commands

Ad hoc commands are commands which can be run individually to perform quick functions. These commands need not be performed later.

For example, you have to reboot all your company servers. For this, you will run the Adhoc commands from ‘/usr/bin/ansible’.

These ad-hoc commands are not used for configuration management and deployment, because these commands are of one-time usage.

Ad-hoc

Ad-hoc-cmd

Options:

• -m specifies we are using the command module of Ansible

• -a specifies we are running an ad hoc command

• -b This allows running the command with sudo privilege

 name This is the name of the package to install

 state This includes the package’s state (present, latest, absent).

Basics of Ansible Playbook

  • A collection of tasks (or plays) written in a file
  • YAML format
  • Standard YAML syntax
  • Multiple plays can be included
  • Task-> Plays-> Playbook

YAML Syntax:

---
- name: This installs and starts Apache webserver
  hosts: webservers
  tasks:
  - name: Install Apache Webserver 
    yum:   name=httpd  state=latest
 - name: check httpd status
    service:   name=httpd  state=started

Your First Playbook:

---
- hosts: webservers
  vars:
    http_port: 80
    max_clients: 200
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: pkg=httpd state=latest
  - name: replace default index.html file
    copy: src=/static_files/index.html dest=/var/www/html/ mode=0644
    notify:
    - restart apache
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
  handlers:
    - name: restart apache
      service: name=httpd state=restarted

Q/A’s from Day 1 live session:

These are some questions that were asked during the Ansible for Beginners day 1 live session. These questions are from Modules 1 & 2.

Q1. Is ansible a RedHat Product?

Ans. Yes, Ansible is a RedHat product, but it is open-source.

Q2. Can we use Ansible in Windows?

Ans. Ansible control node can be installed only on a Linux machine, but it can manage Windows nodes via Windows Remote Management.

Q3. What is the Ansible control node?

Ans. A control node is a Linux server with Ansible installed on it and is used to manage remote hosts or nodes. These remote systems are known as Managed Hosts or Managed nodes.

Q4. What is Module in Ansible? 

Answer: A module is a reusable, standalone script that Ansible runs on your behalf, either locally or remotely. Modules interact with your local machine, an API, or a remote system to perform specific tasks like changing a database password or spinning up a cloud instance.

Q5. What is ansible.cfg file?

Answer: This is the brain and the heart of Ansible, the file that governs the behavior of all interactions performed by the control node. In Ansible’s case, that default configuration file is (ansible. cfg)

Q6. What is EPEL?

Ans. EPEL stands for Extra Package for Enterprise Linux. The EPEL repository is a community-supported repository hosted by the Fedora Community project. The EPEL repository is not a part of Red Hat.

Q7. What is the difference between static & dynamic inventory?

Ans. In Ansible, a static inventory file is a plain text file that contains a list of managed hosts declared under a host group using either hostnames or IP addresses.

In a configuration – especially a cloud setup such as AWS where the inventory file keeps constantly changing as you add or decommission servers, keeping tabs on the hosts defined in the inventory file becomes a real challenge. It becomes inconvenient to go back to the host file and update the hosts’ list with their IP addresses. And this is where a dynamic inventory comes to play

Q8. If we add new code to the Ansible configuration does the server need a reboot?

Ans. No, configuration changes are applied using ansible binary & the OS does not need a reboot.

Q9. What is the Ansible playbook?

Ans. An Ansible playbook is a blueprint of automation tasks—which are complex IT actions executed with limited or no human involvement. Ansible playbooks are executed on a set, group, or classification of hosts, which together make up an Ansible inventory.

Q10. Do all managed nodes require python? 

Ans.  Yes, all managed nodes require python to be managed by Ansible. 

Quiz Questions!

Check out these questions and see if you can answer them

Question: What language is Ansible playbooks are written in by default?

a. JSON format

b. YAML format

c. XML format

d. HTML format

Comment your answer in the comment box.

The right answer will be revealed in my next week’s blog.

References

Next Task For You

If you are considering in-depth learning about Ansible in the coming days, then do join our WAITLIST and don’t miss an opportunity to attend a free class and gain a plethora of insights on the basics of Ansible.

ansible

Share This Post with Your Friends over Social Media!

The post Ansible for Beginners Day1 Live Session Review and Q/A appeared first on Cloud Training Program.


Viewing all articles
Browse latest Browse all 1891

Trending Articles