technical skills grow

Responsive Ads Here

Friday, October 1, 2021

AUTOMATION WITH ANSIBLE

Chapter 1- What is Ansible? 

CHAPTER 1- AUTOMATION WITH ANSIBLE  

CHAPTER 2-Install & configure ansible server nodes for manage inventory  

Chapter 3-Performing Ad Hoc Commands with Ansible 

CHAPTER 4-IMPLEMENTING PLAYBOOKS

 

Ansible is an open source automation platform. It's a simple automation language that can perfectly describe an IT application infrastructure in Ansible Playbooks. It's also an automation engine that runs Ansible Playbooks

Ansible Is Simple Ansible Playbooks provide human-readable automation. This means that your playbooks are automation tools that are also easy for humans to read, comprehend, and change. No special coding skills are required to write them. Playbooks execute tasks in order. The simplicity of playbook design makes them usable by every team. This allows people new to Ansible to get productive quickly.

 Ansible has a number of important strengths:

Cross platform support: Ansible provides agentless support for Linux, Windows, UNIX, and network devices, in physical, virtual, cloud, and container environments. 

Human-readable automation: Ansible Playbooks, written as YAML text files, are easy to read and help ensure that everyone understands what they will do 

Perfect description of applications: Every change can be made by Ansible Playbooks, and every aspect of your application environment can be described and documented. 

Easy to manage in version control: Ansible Playbooks and projects are plain text. They can be treated like source code and placed in your existing version control system

Installing Ansible :

 • We are going to Install Ansible on server which is control all node .The control node should be Linux / Unix . Window is not support as control node.

Needs: Python 2 ( V 2.6 or later). Not recommend to install Python V3 on production with Ansible.

Step 1. Install python 

root@Master_node ~]# yum list installed python

root@Master_node ~]# sudo yum install -y ansible

root@Master_node ~]# mkdir inventory 

root@Master_node ~]# cd inventory

root@Master_node ~]# vim master_node 
[dev] 
node1.example.com
 
Note : Close this file and check using this command

root@Master_node inventory ]# ansible dev -i inventory --list-hosts

Milestone 1.

The Inventory:

An inventory defines a collection of hosts that Ansible will manage. These hosts can also beassigned to groups, which can be managed collectively.
 
Host inventories can be defined in two different ways. 
1. static host inventory can be defined by a text file.
2. dynamic host inventory can be generated by a script or other program.
 
Static Inventory : A static inventory is a list of host names or IP addresses of managed hosts,each on a single line: 

root@Master_node ~]# mkdir inventory  

root@Master_node ~]# cd inventory

root@Master_node ~]# vim master_node 
[dev] 
host1.example.com 
host2.example.com 
host3.example.com 
db1.example.com
db2.example.com 
192.0.2.42
 
In the following example, the host inventory defines two host groups, webservers and db-servers.
 
[webservers] 
web1.example.com
web2.example.com 
192.0.2.42 
[db-servers]
db1.example.com 
db2.example.com
[production]
web1.example.com 
web2.example.com 
db1.example.com 
db2.example.com

Defining Nested Groups

Ansible host inventories can include groups of host groups. This is accomplished with the:children suffix. The following example creates a new group called north-america, whichincludes all of the hosts from the usa and canada groups.
  
[usa]
washington1.example.com
washington2.example.com
[canada] 
ontario01.example.com 
ontario02.example.com 
 
[north-america:children] 
canada
usa 
 
Testing the Inventory
[user@demo ~]$ ansible washington1.example.com --list-hosts hosts (1): washington1.example.com
 
You can run the following command to list all hosts in a group: 
[user@demo ~]$ ansible canada --list-hosts 
              hosts (2): 
              ontario01.example.com 
              ontario02.example.com   

Simplifying Host Specifications with Ranges :

Ranges match all the values from START to END, inclusive. Consider the following examples: 

192.168.[4:7].[0:255] will match all IPv4 addresses in the 192.168.4.0/22 network(192.168.4.0 through 192.168.7.255).

 server[01:20].example.com will match all hosts named server01.example.com through server20.example.com.   

Milestone 2.

Managing Ansible Configuration Files

The recommended practice is to create an ansible.cfg file in a directory from which you run Ansible commands. This directory would also contain any files used by your Ansible project, such as an inventory and a playbook. This is the most common location used for the Ansible configuration file. It is unusual to use a ~/.ansible.cfg or /etc/ansible/ansible.cfg file in practice.

Steps 1. 

Create the /home/tom/dep-manage  directory, which will contain the files for this exercise. Change to this newly created directory.

[root@control ~]$ mkdir /home/node/dep-manage 

[root@control ~]$ cd /home/node/dep-manage

 Step 2.
In your /home/node/dep-manage  directory, use a text editor to start editing a new file, ansible.cfg.
 
 [root@control dep-manage]$vim ansible.cfg
                    [defaults]
             inventory = ./inventory 
 Save your work and exit the text editor.

 3. In the /home/node/dep-manage  directory, use a text editor to start editing the new static inventory file, inventory.

  
[root@control dep-manage]$vim inventory

   [local]      
  localhost
  [intranet_web]
  servera.example.com
  [everyone:children] 
  local
  intranet_web

Note:  Create the privilege_escalation section in the /home/node/dep-manage/ansible.cfg

[defaults] 
inventory = ./inventory
[privilege_escalation]
become = true                         
become_method = sudo 
become_user = root 
become_ask_pass = true
 
Setting
1. Enable privilege escalation by setting the become
2.Set the privilege escalation to use sudo by setting the become_method directive to sudo 
3.Set the privilege escalation user by setting the become_user directive to root.

No comments:

Post a Comment

Powered by Blogger.

Labels

Contact Form

Name

Email *

Message *

Search This Blog

Blog Archive

Ad Code

Responsive Advertisement

Recent Posts