Serverspace Black Friday
DF
June 1, 2023
Updated June 1, 2023

Install and Setup Ansible on Ubuntu

Ansible Ubuntu

Ansible has revolutionized the automation of technology processes and application deployment using software tools, making it one of the leading trends in this field. As an open-source tool, Ansible provides a seamless method for managing configuration, software, and application deployment on different hosts. Despite its ability to automate complicated multi-tiered IT application environments, Ansible is user-friendly.

Installing and Configuring Ansible

Updating package database's local cache using:

sudo aptitude update

Simplify management tasks by adding "package software-properties-common" and software sources provided by third-party vendors with this :

sudo aptitude install software-properties-common

Personal package archives (PPAs) may be managed by this tool and distribute software packages, utilities.

Next, type in below to include the specified addition Ansible PPA repository:

sudo aptitude-add-repository ppa:ansible/ansible

Refresh the package database using following, then continue install Ansible:

sudo aptitude update
sudo aptitude install ansible

Consequently, the server will have Ansible software, which is essential for managing hosts.

Setup SSH for accessing a managed host

The primary means of communication between Ansible and client servers is through SSH.

This quiz employs SSH keys as they streamline the connection procedure and offer enhanced security when compared to passwords.

To generate an SSH key for the purpose of connecting to hosts, utilize this command:

ssh-keygen -t rsa -b 4096

Copy this generated key to each host that Ansible services using:

ssh-copy-id user@ipaddress

For example: ssh-copy-id root@172.170.100.1
Using a text editor, open the following configuration file:

nano /etc/ansible/hosts

Using the following syntax where group_name is a convenient name for the server group and server_1 and server_2 are the IP addresses of the serviced servers, add lines to the opened hosts file:


[group]
server_1
server_2
For example:
[servers_test]
172.170.100.1
172.170.100.2

Save the changes and exit the file.

Note: Each host must have the python language and python-aptitude package installed:

aptitude-get install python python-aptitude

Check Connection

Ansible typically establishes a connection to the remote host using the root user as the default.

If you are using another user, additional settings are required.

Create a structure's directory in the configuration where YAML files for each group will be located:

sudo mkdir /etc/ansible/groups

Create a group subdirectory with its respective name:

sudo nano /etc/ansible/group_vars/groupname

For example:

sudo nano /etc/ansible/group_vars/servers_test

Insert the following line, replacing "user" with the actual username:

ansible_user: "user"

Save the changes.
Note: individual hosts can be configured by creating aliases and files with corresponding names to their alias in the /etc/ansible/host_vars directory.

Run the following command to check the connection:

ansible -m ping all

Expected result:


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

Conclusion

In this short quiz installed Ansible on Ubuntu and setup it to manage Linux servers.

Vote:
4 out of 5
Аverage rating : 4
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.