Ansible is an
Furthermore, Ansible is an agentless push model software. This means that our host machines do not have to install any software to work, and Ansible pushes its commands directly to its hosts from the central server via SSH. This makes it easy to use and set up, which makes it a very popular software.
Now that we know what Ansible is, we need to use it. For that, we will follow the commands below.
We will first go to the official Ansible website and click on our machine's operating system link. In this Answer, we will follow the installation process for Ubuntu.
Now we will follow the instructions given to install Ansible on our machine.
Now let us proceed to the configuration aspect of our setup.
After installation, we can head to our "/etc/ansible" directory to interact with our Ansible files. Here, we can create another folder named "playbooks" to store our YML scripts for what we want to automate.
--| etc/ansible--| ansible.cfg // configuration file--| hosts // stores hosts--| roles // stores processes--| playbooks // stores scripts
Let's first open our "ansible.cfg" file and locate the commands given below. We must modify them by either uncommenting them and/or setting them to False
depending on our Ansible version. This allows us to bypass host key checking, removing a security layer. This is not recommended, but setting up the host key is unnecessary for our test setup.
host_key_checking=False
Note: If this line of code is not in our configuration file, we can run the following command to create an updated configuration file with all plugins installed: ''
ansible-config init --disabled -t all > ansible.cfg
"
Now we can set our hosts by modifying our "hosts" file. In this, we can either add our remote system's IP or create a group within which we can add multiple remote system IPs. A sample code is provided below.
[EducativeGroup]172.17.0.1 # remote machine IP(s)[EducativeGroup:vars]ansible_password=root@123 # remote machine password
Now we can run CLI code (ad-hoc command) on all machines under our EducativeGroup
and work on all machines through the central server. An example command is shown below.
ansible EducativeGroup -m ping
A playbook accomplishes the same thing we have done through the CLI; however, it is just a more organized method.
--| Playbook--| Plays--| Tasks
We can implement this playbook method by following the steps given below.
Open "etc/ansible/playbooks" and create a YML file. We can name it anything, but for our example, we will use filename
.
Now let us see what our YML file looks like.
# Playbook---# Play- name: filenamehosts: EducativeGroup# Taskstasks:- name: install nano## Moduleapt:name: nanostate: latest
Now we can open our terminal inside the playbook and run the following command to run our playbook.
sudo ansible-playbook filename.yml
Ansible provides an easy solution to mundane and repetitive tasks. It also ensures consistency while managing multiple remote IPs and groups. Overall, Ansible is a great automation tool that allows quick actions on multiple remote machines and prevents any potential human errors.
Free Resources