0% found this document useful (0 votes)
142 views8 pages

Ansile Office Document

Ansible is an open source tool for automating IT tasks like application deployment, cloud provisioning, and configuration management. It connects to machines through SSH and runs tasks defined in YAML playbooks without requiring an agent. Playbooks allow users to automate software installations and deployments across multiple servers using a simple language.

Uploaded by

shrinath bhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
142 views8 pages

Ansile Office Document

Ansible is an open source tool for automating IT tasks like application deployment, cloud provisioning, and configuration management. It connects to machines through SSH and runs tasks defined in YAML playbooks without requiring an agent. Playbooks allow users to automate software installations and deployments across multiple servers using a simple language.

Uploaded by

shrinath bhat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Ansible is an open source tool that helps in task automation, application deployment, cloud provisioning and

configuration management.

So we are talking about IT orchestration where tasks are run in sequence in several different machines or
servers.
Ansible does this by connecting to multiple machines through SSH and runs the tasks which have been
configured into playbooks and uses a simple language called YAML (Yet Another Markup Language).

What You Will Learn: [show]


Overview Of Ansible
Most importantly Ansible does not use an agent to automate tasks on different machines.
Ansible ensures maintaining exact versions and up to date information to the software packages.
For Example, if you want to install JDK 8 or Tomcat or any other software package in 10 or 20 different
machines it is not actually feasible to go to all the machines and install them rather use Ansible to automate
the installation or even software deployments using Playbooks and Inventory written in a very simple
language.
So Ansible is:
 Free and Open Source
 Maintained by Redhat
 Essentially a server configuration
 Configuration Management

Ansible Installation Process


Ansible can be installed and run from any machine.
Typically you will need a Control machine for installation which should be Linux. Windows machine does not
support being a control machine. The control machine will manage the other remote machines. As mentioned
earlier Ansible uses SSH to manage remote machines.
Throughout this tutorial, I will be using AWS EC2 instances to showcase the examples. I have used 2 instances
(one control machine and other as a target for automating tasks) and Redhat Linux 7.5.
Whether on-premise or cloud instances you will need to open ports appropriately based on the tasks being
automated. I have the following ports open as a part of the security group for the EC2 instances to
demonstrate the examples mentioned in the tutorial.
In the above screen, I have mentioned opening port 8080 as I will be showing about automating software
deployment automation using Tomcat which will be useful from a DevOps point of view, especially during the
continuous delivery process.
Installation of Ansible using YUM
As mentioned before I will be using one control machine and a target machine. To start with installation,
perform the steps as shown below in both the machines.
a) Create a common id on both the machines, for Example, ansible with SUDO privileges. This id will be used
for communicating across all the machines involved for automation of tasks.
# useradd ansible
# passwd ansible
b) Edit the /etc/ssh/sshd_config file on the control machine and uncomment out the lines
forPasswordAuthentication and PermitRootLogin
Perform the above steps on both the machines. Once completed, restart the sshd service on both the
machines.
# systemctl restart sshd
c) For complete automation of tasks, we will need passwordless SSH authentication else the whole process will
not be used if you have to key in the password every time.
So post the changes done above if we run the command ssh <target machine> and ssh <control machine> we
will need to key in the password every time which is not the right procedure to execute Ansible tasks.
d) To enable passwordless authentication to perform the steps shown below. Firstly add the user ansible to
the /etc/sudoers file on both the machines which will enable the user ansible to run any command which
requires root privileges.

Save and exit the file after adding the user.


e) Going forward we will use the user ansible to perform all the steps. So switch to the user ansible.
Control Machine su – ansible AND Target Machine su – ansible

Control Machine ssh-keygen


Target Machine ssh-keygen

Copy the ssh key to the target machine and vice versa.
Control Machine ssh-copy-id <IP-Address-Host-Machine>
Target Machine ssh-copy-id <IP-Address-Control-Machine>

We are now able to log in without entering the password. After the check out of the ssh connectivity on both
the machines and be logged in as ansible user.
Control Machine: ssh ansible@<IP-Address-Host-Machine
Target Machine: ssh ansible@<IP-Address-Control-Machine>

Step 1: Install Python on RHEL 8

Install and Set your default Python on RHEL 8 using the guide below.

If you’re using Python3, install python3-pip package.


sudo yum -y install python3-pip
sudo pip3 install --upgrade pip

Step 2: Install Ansible on RHEL 8

Once you have Pip installed, use it to get Ansible installed in your RHEL 8 machine.

$ pip3 install ansible --user

You can see Ansible installed using the following command:

$ ansible --version

Testing Ansible on RHEL 8

To test Ansible, you should have OpenSSH service running on the remote server.

$ sudo systemctl status sshd

Create Ansible inventory file, go to the location and create a file hosts by this path /etc/ansible/

$ vim hosts

Copy the IP address of your remote server(s) to manage and add to Ansible inventory file.
[web]
192.168.122.197

[db]
192.168.122.198

[staging]
192.168.122.199
192.168.122.200
192.168.122.201

Check is there any file called ansible.cfg : If that file is not there create a file in the /etc/ansible/

Get the content from the specified location and paste those details in the ansible.cfg file .

https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg

Generate SSH key and copy it to remote servers.

$ ssh-keygen
$ ssh-copy-id [email protected]

The -i option is used to provide path to inventory file. You should get the same output for hosts group name.

$ ansible -i hosts web -m ping


192.168.122.197 | SUCCESS => {
"changed": false,
"ping": "pong"
}

Write a playbook to copy the file remote server to managed hosts


sudo touch /etc/ansible/sample.txt
sudo chmod 755 /etc/ansible/sample.txt
sudo vi /etc/ansible/copyplaybook.yml

- hosts: all
tasks:
- name: Ansible copy file to remote server
copy:
src: ~/sample.txt
dest: /tmp

ansible-playbook /etc/ansible/copyplaybook.yml

You might also like