About Me

My photo
Kalyan Kumar Pasupuleti B-Tech(Information Technology). • AWS Certified Solutions Architect - Associate • RedHat Certified Engineer(RHCE) • Directory Services and Authentication Certificate of Expertise(LDAP) • Red Hat SELinux Policy Administration Certificate of Expertise(SELinux) • Network Services Security Certificate of Expertise (Network Services) • RedHat Certified Virtualization Administrator(RHCVA) • Red Hat Certified Security Specialist (RHCSS) Working as Cloud DevOps engineer

Sunday, June 21, 2020

Install Ansible on Centos 7

What is Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.

Advantages of Ansible

Free: Ansible is an open-source tool.
Very simple to set up and use: No special coding skills are necessary to use Ansible’s playbooks (more on playbooks later).
Powerful: Ansible lets you model even highly complex IT workflows.
Flexible: You can orchestrate the entire application environment no matter where it’s deployed. You can also customize it based on your needs.
Agentless: You don’t need to install any other software or firewall ports on the client systems you want to automate. You also don’t have to set up a separate management structure.
Efficient: Because you don’t need to install any extra software, there’s more room for application resources on your server.

Prerequisite

Generate ssh key and copy the public key to ansible server and client machines

# ssh-keygen
# ssh-copy-id -i .ssh/id_rsa.pub root@<machine ip>


Step 1 — Installing Ansible

To get Ansible on CentOS 7, first ensure that the CentOS 7 EPEL repository is installed:

# sudo yum install epel-release
Once the repository is installed, install Ansible using yum:

# yum install ansible


Step 2 — Configuring Ansible Hosts

Ansible keeps track of all of the servers that it knows about through a “hosts” file. We need to set up this file first before we can begin to communicate with our other computers.

# vi /etc/ansible/hosts

[ansible_server]
alias ansible_ssh_host=your_server_ip

Save and exit

Now try to ping your list of machines using group name:

# ansible -m ping ansible_server or ansible -m ping all

alias | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

Step 3 — Create your first ansible playbook

# cat vim.yml
---
- hosts: ansible_server
  remote_user: root
  tasks:
   - name: Installing vim
     yum: pkg=vim

Now execute your playbook(Specify the group name where you want to execte the playbook)

# ansible-playbook -l ansible_server vim.yml

PLAY [ansible_server] ****************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************
ok: [alias]

TASK [Installing vim] ****************************************************************************************************************
changed: [alias]

PLAY RECAP ***************************************************************************************************************************
alias                      : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0