Wednesday, July 18, 2018

Ansible Certification : 1. Introducing Ansible

1.   Introducing Ansible 

  • Overview of Ansible Architecture. 
  • Overview of Ansible Deployments.
  • Describing Ansible Inventory
  • Summary . 
  • Quiz Details 
  • Logs 

=======================================================================

INTRODUCING ANSIBLE
Ansible was originally written by Michael De Haan, the creator of the Cobbler provisioning application. Ansible is globally accepted because its easy to use and is built on Python. Ansible is also supported by Devops tools such as Vagrant and Jenkins. 
A file that contains a series of plays is called a playbook. Ansible is an open source configuration managment and orchestration utility. Ansible architecture is agentless. Work is pushed to remote hosts when Ansible executes. 

Modules are the actual programs which performs the actual work of the tasks in play. Ansible is immediately useful because it comes with hundreds of core modules that perform the system administrative tasks. 
What Ansible cannot do ? 
- Ansible cannot audit changes made on the system by other users. 
- Ansible can add packages to the system but it cannot add initial minimal installation of the systems. 
- Ansible can remediate system configuration file drift, it does not monitor it. 
- Ansible does not track what changes are made to the system from last deployment. 
ANSIBLE CONCEPTS AND ARCHITECTURE : 
2 types of machines in the ansible architecture. 
- The control node 
- The manged node 
Control node is where all the software resides. This is the command center for ansible. 
Ansible uses SSH as a network transport to communicate with the managed hosts. The module referenced in the playbook are copied to the managed hosts. Then they are executed in order, with the arguments specified in the playbook. 
Ansible control node components 
- Ansible Configuration : 
  Ansible has configuration setting which defines how it behaves. These settings include such as remote user + command execution. Providing password and sudo credentials while executing remote commands. Default configuration values can be overwritten by Env values and Values defined in Conf files. 
- Host Inventory : 
  The Ansible hosts inventory defines which configuration groups hosts belongs to. The inventory can define how Ansible communicates with the given hosts, 
- Core Modules  :
  Core modules are the modules that are shipped with Ansible. There are 400 core modules. 
- Custom Modules : 
   User can extend Ansible's Functionality by writing there own modules. Modules are typically written in Python, but user also has a option of writing the module in other languages like Perl, shell , Ruby etc. 
- Playbooks : 
   Ansible playbooks are files that are written in YAML Syntax that define the modules with arguments to apply with managed nodes. 
- Connection Plugins : 
   Plugins that enable communication with managed hosts or private cloud. These include native SSH, Parimiko ssh, and local. Parimiko is a python implementation of Openssh with RHEL6 that provides control persist setting to improve performance of Ansible. 
- Plugins : 
  Extensions that enhances Ansible's functionality. Examples emails, notification and logging. 
Roles and requirements for Control Node : 
Python 2.6 or Python 2.7 should be installed on control node. Configuration Files are maintained on Control node. 
Roles and requirements of Managed hosts: 
A managed hosts is a system into which ansible logs into and executes remote commands to perform configuration tasks. Ansible uses SSH so ssh must be configured to accept Nodes connections. Python-simplejson packaged needs to be installed on RHEL 5 version. Python 2.5 covers this package by default. 
QUIZ : 


1.  Which of the following programming language is Ansible built on ? 
  • C ++
  • Perl 
  • Python 
  • Ruby 
2.  Which of the following terms best describes Ansible's Architecture ?
  • Agent-less.
  • Client/Server 
  • Event-Driven
  • Stateless. 
3.  What is the network Protocol which Ansible uses to communicate with managed hosts ?
  • HTTP 
  • HTTPS
  • Paramiko 
  • SNMP 
  • SSH 
4.   Which of the following files defines the action Ansible performs on Managed nodes ?
  • Configuration Files. 
  • Host Inventories. 
  • Manifest 
  • Playbooks. 
  • Script. 
5.  What syntax is used to define Ansible Playbook ?
  • Bash 
  • Perl 
  • Python 
  • YAML 
Note : The serial keyword can be used to limit the number of hosts that the playbook runs at once. Once the subset of servers have been deployed and are functioning properly. Ansible will move onto another batch of server in the target group. By default, Ansible will try to apply playbook to the target managed hosts in parallel, with the exact number of parallel processes to spawn controlled by forks directive mentioned in the applicable ansible.cfg configuration files. 


Ansible Connections Plugins : 

Control Persist  : Connection plugins allow Ansible to communicate with managed hosts and cloud providers. The preferred connection plugins for newer version of Ansible is the native SSH options. Ansible uses control persist option when the client open-ssh supports it. 

Local Connection Plugin : Its used locally, mostly the use case for these types of scenarios are using a corn job to trigger a Ansible locally. 

Paramiko : It is used on RHEL 6. It's a connection solution for older systems where older version of open-ssh didn't had Control Persist. 

Winrm : Ansible connection plugin module allows Microsoft windows machines to be managed. The pywinrm needs to be installed on Linux machine to manage windows hosts. 

Docker connection plugin : Ansible 2 introduced docker as a plugin module which helps in communicating with the docker system without any SSH enabling on the client. 
QUIZ : 


1. Which of the following is not a deployment task suitable for Ansible ?
  • - Deploy JBOSS consistently over different operating system. 
  • - Deploy Red Hat Satellite agents to existing servers in Datacenter 
  • - Discover the operating system version and software subscription status of RHEL. 
  • - Monitor the state of the system so that it does not experience configuration Drift . 
  • - Manage the software development life cycle of Openshift Enterprise Application. 
2. Which of the following Ansible Keyword facilitates zero-downtime rolling updates to occur by limiting the number of managed hosts a playbook can run on in parallel ?
- accelerate 
- gather_subset
- handlers
- serial 
- tasks. 
3. The paramiko Ansible connection plugin is used to communicate with which types of managed hosts ? 
- Docker containers.
- RHEL6
- RHEL7
- Windows Server


Describing Ansible Inventories: 

Ansible Inventories :
Ansible inventories are nothing but the host entries which ansible is going to manage. Hosts may belong to certain group which are identical to the pattern in Data-center. A host can be a member of more than one group.

2 types of host inventories :

  • Static Inventory - its a text file .
  • Dynamic Inventory - generated from outside providers. 

Static Host Inventories : 

An ansible static hosts is basically nothing but a txt file which is created to manage hosts and create groups for the ease of work. 
In the hosts file every server entry needs to be entered on a new line. You can put hostname or IP address. Host group needs to be defined within square brackets [ ]. 

Example : 2 groups are defined in the below hosts files.

# cat /etc/ansible/hosts
[webserver]
localhost
web1.example.com
web2.example.com:2233 ansible_connection=ssh ansible_user=goko
10.10.10.10

[database]
web1.example.com
db1.example.com

In the above example we can see that web2 is given directives that it has to use port 2233 and use ssh for connection and user used for login should be goko

Default location for hosts file :      /etc/ansible/hosts
Can be specified directly by using -i option or --inventory

2 groups can be clubbed together under a Parent group by using :children suffix.

Example as below :

# cat /etc/ansible/hosts
[auto]
hyundai
honda

[tyre]
mrf
apollo

[car:children]
auto
tyre

Now lets work on simplifying the work with hosts file if you have to deal multiple hosts which are in same range or have things in common.

Syntax : [start:end]

192.168.[4:6].[0:255]
server[1:10].example.com         --> server1 to 10 all are covered in here.

Now that we know most of the stuff on Ansible host inventories (static) let try some commands to help us find them at runtime.

$ ansible server1.example.com --list-hosts
---- > server1.example.com

$ ansible server01.example.com --list-hosts    -- > failed example.
---- > no output .

Defining variables in hosts files: 

Even though ansible allows you to specify the variables in hosts file but it is advisable to put them in specific directories.

Dynamic host inventory : 

This inventory can be dynamically generated. Source can be anything like cobbler, cloud, cmdb, cloud.


QUIZ: 

1. Which of the following items is not found in the Ansible inventory files ?

  • Hosts group 
  • IP Address range 
  • Module names 
  • Variable definitions 
  • User authentication information. 
2. cat /etc/hosts
    [linux-dev]
    cchang.example.com
    rlocke.example.com

    [windows-dev]
    wdinyes.exmaple.com

    [development:children]
    linux-dev
    windows-dev

Given the ansible inventory above, which hosts groups include rlocke.example.com ?
  • linux-dev
  • windows-dev
  • development
  • both linux-dev & development.

3. Which of the following expressions can be used in an ansible inventory file to match hosts in the 10.1.0.0/16 address range ?
  • 10.1.0.0/16
  • 10.1.[0:255].[0:255]
  • 10.1.[0-255].[0-255]
  • 10.1*
4.  Which of the following can be a source for Ansible dynamic host inventory information ?
  • Cobbler system information 
  • Configuration management system 
  • LDAP Database
  • Scripts that fetch information from Cloud 
  • All of the above. 


QUIZ : 

1. The python-simplejson package must be installed on which of these nodes ?

  • Ansible control node. 
  • RHEL 5 
  • RHEL 6 
  • RHEL 7 
  • Windows managed hosts 
2.  What is the default location of Ansible hosts file ?
  • /etc/ansible/inventory
  • /etc/ansible/hosts
  • /etc/ansible/hosts.groups
  • /etc/ansible/hosts.inventory. 









Tuesday, July 17, 2018

Ansible Certification [EX407] - Index Page



Introduction 

        • Automation with Ansible. 

1.   Introducing Ansible 

  • Overview of Ansible Architecture. 
  • Overview of Ansible Deployments.
  • Describing Ansible Inventory
  • Summary . 
  • Quiz Details 
  • Logs 


2. Deploying Ansible. 


  • Installing Ansible.
  • Managing Ansible Configuration Files.
  • Running Ad Hoc Commands.
  • Managing Dynamic Inventories.
  • Summary
  • Lab:
  • Exercise


3.   Implementing Playbooks


  • Writing YAML Files
  • Implementing Modules.
  • Implementing Ansible Playbooks
  • Summary
  • Lab
  • Exercise


4. Managing Variables and Inclusions


  • Managing Variables
  • Managing Facts
  • Managing Inclusions
  • Summary
  • Lab
  • Exercise


5.    Implementing Task Control.


  • Constructing Flow Control
  • Implementing Handlers.
  • Implementing Tags
  • Handling Errors
  • Lab
  • Summary



6.     Implementing Jinja2 Templates.


  • Describing Jinja2 Templates.
  • Implementing Jinja2 Templates.
  • Summary
  • Lab
  • Exercise


7.     Implementing Roles.


  • Describing Role structure
  • Creating Roles.
  • Deploying Roles with Ansible Galaxy
  • Summary
  • Lab
  • Exercise


8.    Optimizing Ansible


  • Configuring Connection Types.
  • Configuring Delegation
  • Configuring Parallelism
  • Summary
  • Lab
  • Exercise.



9.    Implementing Ansible Vault.


  • Configuring Ansible Vault
  • Executing with Ansible Vault
  • Summary
  • Lab
  • Exercise


10.    Troubleshooting Ansible


  • Troubleshooting Playbooks
  • Troubleshooting Ansible Managed Hosts
  • Summary
  • Lab
  • Exercise


11.   Implementing Ansible Tower


  • Describing Ansible Tower
  • Deploying Ansible Tower
  • Configuring Users in Ansible
  • Managing Hosts in Ansible Tower
  • Managing Jobs in Ansible Tower
  • Summary
  • Lab
  • Exercise


12. Implementing Ansible in Devops Environment


  • Provisioning Vagrant Machines
  • Deploying Vagrant in a DevOps Environment.
  • Summary
  • Lab
  • Exercise


13.   Automation with Ansible


  • Review
  • Labs