HomeBlogsHow to Install Ansible on Ubuntu Server

How to Install Ansible on Ubuntu Server

Hi everyone, in this article we will show you how to install Ansible on Ubuntu Server. Server automation plays an essential role in system administration due to the throwaway nature of modern application environments. Configuration management tools like Ansible are typically used to streamline the process of automating server setup by setting up standard procedures for new servers, while reducing human errors associated with manual setup.

Ubuntu Desktop is a Linux distribution developed by Canonical, which is one of the most popular distributions thanks to its ease of use. It is also one of the first choices for people starting with Linux operating system. The server edition, which we won’t focus on here, is also used on most Internet servers. There are many Linux Distros for Gaming also that you might don’t know.

Ansible is an open source automation tool for deployment, application deployment (in this case WordPress) and configuration management. Gone are the days of SSHing into the server to execute a command, or hacking together bash scripts to automate tedious tasks. Whether you’re managing a single server or an entire fleet, Ansible can simplify the process and save you time. So what makes Ansible so great?

Like SpinupWP, Ansible is completely agentless, meaning you don’t need to install any software on your remote servers (also known as managed hosts). All commands are executed through Ansible via SSH. If Ansible needs to be updated, you only need to update your single control host, not the remote hosts. The only requirement for running Ansible commands is to install Python on your control host.

Installing Ansible on Ubuntu Server

Step 1: Installing Controlling Machine – Ansible

  • Before installing ‘Ansible‘ on the server, let’s first verify the details of the server like hostname and IP Address. Login into server as a root user and execute the below command to confirm system settings that we’re going to use for this setup.

# sudo ifconfig | grep inet

  • Once you confirm your system settings, it’s time to install ‘Ansible’ software on the system.

Step 2: On Ubuntu/Debian/Linux Mint

  • Here we are going to use official Ansible PPA repository on the system, just run the below commands to add the repository.

$ sudo apt-add-repository ppa:ansible/ansible -y$ sudo apt-get update && sudo apt-get install ansible -y

Step 3: On RHEL/CentOS/Fedora

  • Unfortunately, there are no official Ansible repository for RedHat based clones, but we can install Ansible by enabling epel repository under RHEL/CentOS 6, 7 and currently supported fedora distributions.
  • Fedora users can directly install Ansible through default repository, but if you are using RHEL/CentOS 6, 7, you have to enable EPEL repo.
  • After configuring epel repository, you can install Ansible using following command.

$ sudo yum install ansible -y

  • After installed successfully, you can verify the version by executing below command.

# ansible –version

Step 4: Preparing SSH Keys to Remote Hosts

To perform any deployment or management from the localhost to remote host first we need to create and copy the ssh keys to the remote host. In every remote host there will be a user account tecmint (in your case may be different user).

  • First let we create a SSH key using below command and copy the key to remote hosts.

# ssh-keygen -t rsa -b 4096 -C “admin@tecmintlocal.com”

  • After creating SSH Key successfully, now copy the created key to all three remote server’s.

# ssh-copy-id tecmint@192.168.0.112# ssh-copy-id tecmint@192.168.0.113# ssh-copy-id tecmint@192.168.0.114

  • After copying all SSH Keys to remote host, now perform a ssh key authentication on all remote hosts to check whether authentication working or not.

Step 5: Creating Inventory File for Remote Hosts

  • Inventory file, This file hold the host information’s like which host we need to get connect from local to remote. Default inventory file will be under /etc/ansible/hosts.
  • Now let’s add these three hosts to inventory file. Open and edit file using your favourite editor, Here I use vim.

# sudo vim /etc/ansible/hosts

  • Add the following three hosts IP address..

192.168.0.112192.168.0.113192.168.0.114

The ‘web-servers‘ in the brackets indicates as group names, it is used in classifying systems and deciding which systems you are going to controlling at what times and for what reason.

  • Now time to check our all 3 server by just doing a ping from my localhost. To perform the action we need to use the command ‘ansible‘ with options ‘-m‘ (module) and ‘-all‘ (group of servers).

# ansible -m ping web-servers

# ansible -m ping -all

  • Now, here we are using another module called ‘command‘, which is used to execute list of commands (like, df, free, uptim, etc.) on all selected remote hosts at one go, for example watch out few examples shown below.
  • To check the partitions on all remote hosts

# ansible -m command -a “df -h” web-servers

  • Check memory usage on all remote hosts.

# ansible -m command -a “free -mt” web-servers

  • Checking Uptime for all 3 servers.

# ansible -m command -a “uptime” web-servers

# ansible -m command -a “arch” web-servers# ansible -m shell -a “hostname” web-servers

  • If we need the output to any file we can redirect as below.

# ansible -m command -a “df -h” web-servers > /tmp/df_outpur.txt

Final Words

We hope you like our article on how to Install Ansible on Ubuntu Server. Ansible is a Powerful IT automation tool which is must every sysadmins for deploying applications and managing server’s at one go. Among any other automation tool such as puppet, Capistrano, salt, Ansible is quit very interesting and very easy to setup for production environment. So, if you like our article then do share it others.

I hope you understand this article, How to Install Ansible on Ubuntu Server.

James Hogan
James Hogan is a senior staff writer at Bollyinside, where he has been covering various topics, including laptops, gaming gear, keyboards, storage, and more. During that period, they evaluated hundreds of laptops and thousands of accessories and built a collection of entirely too many mechanical keyboards for their own use.

RELATED ARTICLES

Must Read

- Advertisment -