Updated May 11, 2023
Introduction to Ansible Install
This is an outline of Ansible Install. Ansible is a software provisioning tool, and it is available as open-source. It can be executed on both UNIX systems and Windows. Additionally, it serves as orchestration management, enabling automatic deployment in various environments. You can execute it on both UNIX systems and Windows. Additionally, it serves as orchestration management, allowing automatic deployment in various environments. It automates the process of application deployment, configuration management, orchestration, and other IT processes. You can see the process of installing Ansible in a different environment here.
Installation of Ansible
The management systems of Ansible should not imply added dependencies on the environment, and it is consistent. It should be able to develop refined and secured environments where Ansible doesn’t enable implementing agents to nodes. To manage the nodes, only Python and OpenSSH are required. The careful composition of Ansible is crucial to ensure reliability and prevent unwanted malware attacks. Ansible is not a tough part; it is easy to learn and implement. Many playbooks use Ansible as descriptive language, purely dependent on Jinja templates and YAML.
To install Ansible, it is mandatory to have dual machines. One is the server, and the other is a node. The server behaves like the user’s managed node, and the node behaves like a controller one.
- As a first step, it is advisable to update the control node.
- It is mandatory to check the existing operating system; its version is updated.
- Give the command to initiate the task.
- To install the EPEL repository, you need to execute the following command. This command installs the most commonly used packages on the system.
Yum, install epel – release.
- After installing the repositories, the installation of Ansible begins. The below screen shows the different package installations from yum and Ansible.
yum install ansible
- You can download Ansible from the EPEL repository.
- A user for Ansible should be created. Then we should create a user who is non-root on both ends, which can be executed on the Ansible playbook. Here, you can provide the username as “Educba” (or any preferred username), but use the same username for both the managed node and controller node.
- The controller node adds the user and creates a password for them.
- To gain access to the managed node, it is necessary to add the admin user and provide the corresponding password.
User add Educba
- Then it is mandatory to set the admin user as an Educba user, as he can easily work on the managed node without any password. Then check on the setup of the key pair of SSH to the user Educba. In the control node, execute the SSH pair by using the command.
Ssh-keygen ( implied to generate keys)
- After generating the keys, copy and paste the public key to the managed node by using the command.
- To locate the managed nodes, the admin user needs to create an inventory and establish a connection between the inventory and managed node by logging in to the control node.
- To choose the insert mode, you can use the “I” command and then add the hostname.
- Then save the file by giving: wq command.
- We’ve prepared a playbook for Ansible that requires installing Nginx on the managed node. Please log in to the controller node using the username “Educba” and create a file with a unique name.
To create the playbook, use YAML and make sure it is easy to read for humans by formatting it correctly.
You can add the text to the playbook by entering the insert mode.
Host : app server
Educba (name of the task)
Educba: install nginx webserver
Apt: Educba: nginx state: start: update_cache: yes: true
Notify: - start nginx
Handlers: start nginx
Service: Educba: nginx
YAML gives multiple files to be present in one or multiple documents and can be placed separately. The YAML file describes a hierarchy composed of hosts, handlers, and tasks. The image below provides the sample playbook, and the user can customize their playbook by using the commands provided below.
We can create multiple tasks, hosts, and handlers in the playbook.
Host: Name of the app server
Educba: install webserver –nginx
Apt: Educba: nginx: init updated_cache: yes
- Run nginx
The executed task perform all the essential operation in the file. The code above contains a “notify” section that has a list with just one labeled item – “run nginx.” Although it doesn’t explicitly state that “run” is an internal command, one can infer that it refers to the handler. Handlers are responsible for executing a function when triggered by a task. They act as tasks or hosts that only execute when instructed by the user or the task running on the client system.
Educba: start nginx
Educba: run nginx
- The above code states that run the nginx handler. It will execute only after the Nginx web server is downloaded. The user can run the playbook into the file called nginx.yml.
- Then save the code and exit by using the command: wq.
- Try to use space instead of tab and ensure that spacing should be consistent with the YAML file to prevent bugs.
- Execute the playbook.
- After executing the playbook, you should copy the link into the created web server. Then, you can create a playbook in the command-line interface. Next, execute any tasks, hosts, and handlers on the webserver hosted on the machine.
The image above shows the home page of the web server. After copying the link, it will display all the tasks created.
In this article, we have seen Ansible and its installation. notifyIt serves as an orchestrated management tool that significantly aids the automation process. You can see more about Ansible and Excel in DevOps, which helps you connect the bridge between operations and developers.
This is a guide to Ansible Install. Here we discuss the introduction and installation of Ansible for a better understanding. You may also have a look at the following articles to learn more –