Introduction to Ansible Install
This is an outline on Ansible Install. Ansible is a software provisioning tool, and it is available as open-source. It can be used for application deployment and configuration management where infrastructure as a code is enabled. It can be executed on UNIX systems and Windows. It is also used as orchestration management, which can be deployed automatically in many environments. It automates the process of application deployment, configuration management, orchestration, and other IT processes. The process of installing Ansible in a different environment is seen 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 to implement agents to nodes. Only Python and OpenSSH are needed to manage the nodes. Ansible is reliable and should be composed carefully to 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 recommended the control node get updated.
- It is mandatory to check the existing operating system; its version is updated.
- Give the command to initiate the task.
- Then EPEL repository should be installed. The following command should be given to install mostly 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
- Ansible is downloaded from the repository of EPEL.
- User for Ansible should be created. Then we should create a user who is non-root in both the end which can be executed on the Ansible playbook. Here we can give the user name as Educba ( user name can be given according to user preference) but the same user name should be provided to both the managed node and controller node.
- Then the user is added to the controller node and the password is created accordingly.
Passwd [email protected]
- Then the admin user is added to the managed node and the password is given accordingly.
User add Educba
Passwd [email protected]
- Then it is mandatory to set the admin user that is Educba user as he can easily work on the managed node without any password. Then check on the set up 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.
- Inventory creation is made to find the managed nodes. In the control node, the admin user can be logged in to link the inventory and managed node.
- Now, give the I command to choose the insert mode, and then the hostname is added.
- Then save the file by giving: wq command.
- Ansible playbook is created. Installation of Nginx is required to create an Ansible playbook in the managed node. The controller node should be logged in with the username as Educba and a file with a unique name should be created.
- The playbook should be composed in YAML and the format should be human-readable.
Now, by entering the insert mode, the text added to the playbook.
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 that is composed of hosts, handlers, and tasks. The sample playbook is given in the below image and the user can customize his playbook by giving the below commands.
In the playbook, we can create multiple tasks, hosts, and handlers.
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 important operation in the file. In the above code, notify has a list with a single item and it is known as run nginx. Here run is not mentioned as an internal command but it can be taken as a reference to the handler which is required to execute a function when it is pulled by a task. Handlers are termed as tasks and hosts which execute only when they are instructed by the user or the task running on the client system.
Educba: start nginx
Educba: run nginx
- The above code states that run 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.
- Then after the execution of the playbook, copy the link into the webserver which was created and there can be a playbook that was created in the command-line interface. Then whatever task, host, and handler created were executed in the webserver hosted on the machine.
The above image is the home page of the webserver and once the link is copied, it displays all the tasks we created.
Conclusion – Ansible Install
In this article, we have seen Ansible and its installation. It can be served as an orchestrated management tool that helps more in the automation process. You can see more about Ansible and excel yourself in DevOps which helps you to connect the bridge between operations and developer.
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 –