Showing posts with label Ansible. Show all posts
Showing posts with label Ansible. Show all posts

Sunday, 18 June 2017

Working With Ansible



Ansible Playbook contains mainly 4 sections.They are
1.Setup
2.Variables
3.Tasks
4.Handlers

Setup section contains the information about Host name(Which we are going to connect),User info(by which user account ansible should establish connection with Managed Machine),Sudo permissions,Connection is ssh or not.These type info will be available in Setup section.



Variables,Tasks and Handlers will be discussed in later posts.

After writing inventory file.we must check SSH connection between the controller machine(CM) and managed machines(MM).We must create SSH connection between CM and MM as follow
create a user name with test in all the 3 VMS and give visudo permissions to it or you can work with root also.Then from server1 generate SSH key and copy it to server2,server3 as follow.

[test@server1 ~]$ ssh-keygen

[test@server1 ~]$ ssh-copy-id server2.abc.com

[test@server1 ~]$ ssh-copy-id server3.abc.com

Now you setup a password less authentication for server1 to server2,server3.It makes to communicate server1 to server2,server3 very simple.

The following command checks ansible connection between CM and MM .Here "webservers" is group name defind in inventory file.Now i can start working with ansible.

This below command confirms the Controler machne and managed machines are having connection.
[test@server1 ~]$ ansible webservers -m ping

server3.abc.com | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
server2.abc.com | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

or i can ping individual server as follow

[test@server1 ~]$ ansible server2.abc.com -m ping


First Playbook

To write the playbook we have some rules to follow
The first line should start with ---
And every comment should start with #.These comments are not be executable.
Every item contains - symbol and space before it starts.The playbook follow a structer. If we doesn't follow that structer it will shows the errors. Every line should follow indentation and spaces at required places.It follows Key:Value Rule.

[test@server1 ansible]$ vi web.yml
To Run the playbook we use following command:

Using syntax check option  will checks the syntax of the playbook like the playbook following indentation and spacing correctly. Check option for dry run means it won't do anything on servers but displays the resulted output.

[test@server1 ansible]$ ansible-playbook web.yml --syntax-check
[test@server1 ansible]$ ansible-playbook web.yml --check 

[test@server1 ansible]$ ansible-playbook web.yml 

This command effects on the servers.output will be as follow

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends. Follow us by email for our new posts 

Thanks

Devops Desk Team

Saturday, 17 June 2017

Ansible Installation

To work with ansible we require some basic Linux commands. Ansible can be installed on linux based systems. Ansible has different versions.I am using  Ansible 2.3 .We can install Ansible in  different ways.In this tutorial i will tell you installation for linux based systems.

First we need to install a repository  "epel-release" before installing ansible. epel-release is a repository with tuns of packages for yum.Then just see the files in the epel-release repository you can see different files in that.
To install epel-release 


To install ansible

Now the actual step comes in  .It will installs latest version of  ansible in your system. goto ansible directory you will see some files.






In above ansible.cfg is called  main configuration file for anisible and inventory file(hosts) contains info about hosts (Managed Machines Ipaddress, hostname). To open the host file we need give the command as follow.

[root@server1 ansible]# vi hosts

It will display a file with a lot of stuff commented.in that give your managed machine name and ipaddress to work with it.you can give any number of machines and you can group those machines also.
Ansible Inventories:
 Ansible is used for managing multiple servers in the Infrastructure. The collection of hosts is known as “Ansible Inventory”.

[root@server1 ~]# more /etc/ansible/hosts

The inventory file can be in any format , The format for /etc/ansible/hosts like (one of Ansible’s defaults) and looks like below.These are the hostnames of the servers i am working with.To know the hostname of your managed machines type the command hostname .These hostnames should be fully qualified domain name(fqdn) like below.

It is ok to put systems in more than one group, for instance a server could be both a webserver and a dbserver. 

if things are not running on the default port then you can provide port number also as follow:
server3.abc.com:5309
Suppose you have static IPs and want to set up some aliases . You can also describe hosts like this:
server2 ansible_port=5309 ansible_host=192.0.2.50
If you have a lot of hosts having the same patterns you can do this:
[webservers]
server1[01:50].abc.com
Host Variables:
it is easy to assign variables to hosts that will be used later in playbooks.These variables known as host variables.
[webservers]
server2 http_port=80 maxRequestsPerChild=808
server3 http_port=303 maxRequestsPerChild=909
Group Variables:
Variables can also be applied to an entire group at once.
If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Ansible Introduction



Ansible-1
Ansible is used to automate the infrastructer in the organization.It is one of the major tool among the devops tools because it makes tedious tasks so simple.Using Ansible we can communicate 100s of servers very easy using secure shell(SSH).
You might wonder how it work?It's simple It work like client-server architecture.Now small organizations to large enterprises using Ansible as their primary configuration management tool in their environment.It communicates with different servers using SSH.
Ansible is purely written in python.It makes Ansible simple and smart. Ansible scripts are known as playbooks.These playbooks contains set of tasks.


It’s simplicity forces everyone to use Ansible as configuration management tool.

 It is a Configuration Management Tool, Provisioning Tool, Orchestration Tool.Ansible uses YAML format. It uses Declarative language. Ansible scripts are called playbooks. These playbooks are saved with extension “playbookname.yml”.Ansible uses two tier architecture .It contains Controller Machines and Managed Machine.
Ansible software is installed on Controller Machine and all the playbooks will be written on controller machine. These playbooks will be pushed to run on Managed Machines. So its called Push based method.
Ansible uses SSH(Secure Shell) to communicate with controller machine.Ansible is purely dependent on Python. To run ansible on controller machine we must have python pre installed. To work with managed machines also managed machines also requires python installed. Ansible playbooks are reusable means we can write playbook once and we can use it several times when we require.
Ansible playbooks are idempotent means. Once we execute a playbook on particular server it will executes the playbook tasks. If run the same playbook on same server it does’t run the same tasks again.it saves time.it is known as idempotency.
Ansible is having rich set of modules. which makes writing playbooks simple.These modules are written in Python.Ansible follows Purely in order execution.To work with ansible controller machine must be a linux based system. Managed machine may be linux, Mac, Windows(For windows it should have power shell 3.0 to be installed, Windows Remote service should be enabled,Python module Winrm to be installed ). Ansible contains two important files those are inventory file(It contains hosts information), ansible.cfg file(This is main configuration file for ansible).

You can follow official documentation from ansible by clicking the below link.


If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference. We will try to help you.

If you like this share with your friends. Follow us by email for our new posts 

Thanks

Devops Desk Team