Table of contents
Ansible is an open-source software provisioning, configuration management, and application-deployment tool which allows you to manage your infrastructure in infrastructure as code (IaC) way. In this article, we’ll cover the installation and initial configuration for Ansible on Ubuntu Linux.
Operation teams and administrators use configuration management tools to simplify the automation process of managing configurations of a large number of servers. By using Ansible you have control over numerous systems from a central location.
The most popular configuration management tools available for you are:
Here’s a chart from Google Trends, which shows the search volume for all of them:
Ansible is very simple, which makes it a favorite tool of choice for many people worldwide. It uses SSH for executing automation tasks described in YAML files.
Ansible also supports containerized workloads and infrastructure deployment automation to private and public clouds.
It does not matter what requirements are for your application; Ansible will take the responsibility of creating, managing, and maintaining everything.
Here are primary use-cases for Ansible:
- Private Infrastructure And Cloud Automation: Ansible is a powerful and handy tool that permits users to handle various physical devices, such as storage devices, bare-metal servers, and even network devices. It is simple to use Ansible’s Playbook-based automation and integrating it with your existing provisioning infrastructure.
- IT Service Management: You can modernize service processes faster and more effectively by automating service requests and offering a single truth source regarding IT asset configurations.
- Virtualization Automation: Ansible supports many leading virtualization industry frameworks, including Vagrant, VMware, Red Hat Virtualization (RHV), vSphere. Ansible can provision virtual worlds, orchestrate and deploy them into any virtual environment.
- Container Automation: Ansible supports the Red Hat OpenShift Container Platform and other container technologies and handles native Kubernetes and Docker container management. Ansible wraps native commands on all of these frameworks, enabling you to automate almost anything.
In the next part of this guide, we will check out installing and configuring Ansible on the Ubuntu system.
To install Ansible on Ubuntu Linux, use the following command:
sudo apt install ansible
Let’s verify successful Ansible installation:
If you’re installing Ansible on a brand new server or Docker container, execute the command to generate the SSH key:
You can press Enter to answer the questions to proceed with the default SSH key configuration, or you can make the required changes.
If you’d like to learn more about SSH, its configuration, and usage examples, I recommend you our article Top 10 SSH features you must know to be more productive.
Ansible host configuration
To unlock the capability to use Ansible for a server or container automation, we need to install an SSH package on it.
sudo apt install openssh-server -y
Check that our server SSH service status is active:
sudo systemctl status sshd
You can also enable the
sshd service if its status is not Active.
sudo systemctl start sshd
If you enabled the UFW firewall, make sure that you did not forget to allow SSH traffic to the host:
sudo ufw allow ssh
Now, we need to add a new user named
sudo adduser ansible
Fill out all the required credentials, including password, full name, etc.
Also, type ‘y‘ in the terminal if you provided the correct information.
Next, we need to set the passwordless access for the
ansible user and him the ability to execute administrative commands:
echo "ansible ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/ansible
Look out for the host IP address where you created the
Let’s copy the public SSH key to the host where we installed Ansible to allow passwordless authentication:
Use the ‘-L‘ option in the
usermod command for disabling the password-based login:
sudo usermod -L ansible
Let’s try to SSH to the host using an
You should not use a password:
Testing Ansible connection to the host
Now, let’s test that we’re ready for Ansible automation.
We need to create a new directory for Ansible.
Jump to the
Add the IP address of the host you want to manage the
Enter the Ansible host IP and saved this file:
Finally, we can ping the host by using Ansible:
ansible all -i ./hosts -u ansible -m ping
SUCCESS refers to the successfully established connection to the Ansible host. In another case,
UNREACHABLE will display if the system found any issue in testing Ansible automation.
Now, you can start developing your Ansible automation playbooks to automate host configuration.
This article has provided you a step-by-step process for installing and setting up the Ansible on Ubuntu. Starting from now, you can work on automation playbooks.
We hope this article was helpful for you. If so, please, help us to spread it to the world.
We’ve obtained the Ansible logo from Wikimedia Commons.
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?
I’m a passionate Cloud Infrastructure Architect with more than 15 years of experience in IT.
Any of my posts represent my personal experience and opinion about the topic.