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:
Simplify management tasks by adding "package software-properties-common" and software sources provided by third-party vendors with this :
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:
Refresh the package database using following, then continue install Ansible:
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:
Copy this generated key to each host that Ansible services using:
For example: ssh-copy-id root@172.170.100.1
Using a text editor, open the following configuration file:
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:
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:
Create a group subdirectory with its respective name:
For example:
Insert the following line, replacing "user" with the actual username:
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:
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.