Tuesday, December 15, 2020

Install Ansible on Centos and http using ansible on client machine

 Description:  Here I have explained, What is Ansible? How to install Ansible on  Centos? How to install  HTTP using Ansible on the client machine?

What is Ansible?

Ansible is an open-source automation software written in Python which is used to deploy software application on client node without an agent.

How to install Ansible on Centos?

Setup:

  1. Ansible Machine [54.166.147.149]
  2. Remote Host [54.209.250.129]

  • Update the System with the latest packages and security patches using below command 
# yum -y update

  • Install the EPEL repository to install required packages 
# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
# yum install epel-release-latest-7.noarch.rpm
# yum update -y 

  • Install Ansible and other required packages using below command 
# yum install git python python-devel python-pip openssl ansible -y



  • Verify ansible version using below command
# ansible --version 



  • Now I am going to create ssh-key and copy it to remote host to manage it using ansible 
# ssh-keygen -t rsa

You will be prompted to provide name and the password for key pair fill the details. Once you filled name and password SSH key file will create 


Copy SSH key from ansible server to the remote host machine using below command 

# ssh-copy-id ec2-user@Ansible_Client_IP_Address

OR

Copy id_rsa.pub file content to all Ansible client-machine from .ssh directory 

# cd .ssh
# cat id_rsa.pub


Copy to the ansible client machine as follow 


Paste key file as follow



Configure Ansible Host 
  • Open Ansible host file from the location /etc/ansible/hosts and add an entry as follow 
[webserver]
172.31.28.116




  • Connect using Ansible and test ping to all given hosts 
# ansible -m ping all




Install Apache on Ansible Host
  • Create runbook on Ansible server as follow 
# vi playbook2.yaml
---
- hosts: webserver
  remote_user: root

  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest


  • Run playbook using below command
# ansible-playbook playbook2.yaml

  • Verify  HTTP after installation in Ansible client machine 



No comments:

Post a Comment