HomeBest Linux ToolsHow To Install and Setup Ansible in Ubuntu

How To Install and Setup Ansible in Ubuntu

Ansible is associate degree open source configuration management, application preparation likewise software package provisioning tool that’s wont to deploy, set up & manage servers. because of ease in mistreatment Ansible is one amongst the simplest & hottest automation tools. It uses YAML, that is straightforward to find out & doesn’t need you to find out a sophisticated programing language like Ruby (used in puppet & chef).

Also, it doesn’t need any agent to be put in on client machines & solely needs client machines to possess python and ssh put ineach of those square measure sometimes offered on systems.

Also Read: How to Reset Ubuntu Passwd in WSL2

Before we tend to move onto install Ansible on Ubuntu, let’s discuss the pre-requisites for Ansible

1- we want a minimum of2 machines, one can act as associate Ansible server & different as a consumerwe will add as severalas the consumer required.

2- Password-less SSH ought to be enabled between the ansible server and consumerthe method to do so is as follows,

Firstly produce associate SSH keypair on Ansible server using the subsequent command,

$ ssh-keygen -t rsa

Two files are going to be created with the preceding command i.e. id_rsa & id_rsa.pub. currently we want to repeat the general public key i.e. id_rsa.pub to the client system. therefore there ar 2 ways that, you’ll be able to either copy the file using SCP command otherwise you can execute the subsequent command from the server,

$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.10.1.100

where 10.10.1.100 is that the scientific discipline address of your client machine. Similarly, copy the file to any or all the client machines. currently before we tend to move on to put in ansible on Ubuntu, certify that we tend to ar ready to ssh to the consumer without any password,

$ ssh root@10.10.1.100

Now The Installation

Install Ansible On Ubuntu

to get the newest ansible version, we’d like to modify the ansible repo 1st. Install the repo with the subsequent command,

$ sudo apt-add-repository ppa:ansible/ansible

Once we’ve got repository enabled, we will currently install ansible server using apt-get,

$ sudo apt-get update -y && sudo apt-get install ansible -y

Configuring Ansible

Next, we want to form a listing file to feature client servers. to try and do that we want to edit the file /etc/ansible/hosts & add the clients within the following syntax,

[group-name]
alias ansible_ssh_host=host_IP_address

where, an alias may be a name given to hosts we have a tendency to adding & it will be something, host_IP_address is wherever we have a tendency to enter the ip address for the hosts. For this tutorial, we have a tendency to square measure aiming to add a pair of clients/hosts for ansible to manage, thus let’s produce an entry for these 2 hosts within the configuration file,

$ vi /etc/ansible/hosts
[test_clients]
client1 ansible_ssh_host=10.10.1.100
client2 ansible_ssh_host=10.10.1.200

Save file & exit it. we tend to are using root to login to different servers however we are able to use different native users similarly & we want to outline it for Ansible no matter user we’ll be using. To do so, we’ll 1st produce a folder named ‘group_vars’ in ‘/etc/ansible’

$ cd /etc/ansible
$ mkdir group_vars

Next, we are going to produce a file named when the group we’ve got created in ‘etc/ansible/hosts’ i.e. test_clients

$ vi test_clients

& add the following information about the user,

ansible_ssh_user: root

Note:– File will start with ‘—’ (minus/dash symbol), don’t forget that

If we would like to use identical user for all the groups created, then we will produce solely one file named ‘all’ to say the user details for ssh login, rather than making a file for each group.

$ vi /etc/ansible/group_vars/all

ansible_ssh_user: root

Similarly, we willstarted files for individual hosts additionally.

Now, the setup for the clients has been done. we’llcurrently push some straightforward commands to any or all the clients being managed by Ansible.

Testing Hosts

To check the property of all the hosts, we are going to issue a command,

$ ansible -m ping all

If all the hosts are properly connected, it should return the following output,

client1 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
client2 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}

We can also issue the command to an individual host,

$ ansible -m ping client1

or to the multiple hosts,

$ ansible -m ping client1:client2

or even to a single group,

$ ansible -m ping test_client

This completes our tutorial on a way to install Ansible on Ubuntu. If any having doubts or queries concerning this post, use the comment box below.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments