Updated March 28, 2023
Introduction to Ansible YAML
Ansible is an open source tool where it can be used as a configuration management tool and deployment tool as well. It is also called as a software provisioning tool. It is widely used as a deployment tool in DevOps culture. It provides a very simple and powerful automation for computer support with regards of platform independent. It is easy to deploy build files or application files as it is an agentless and have security infrastructure. It is also used for system admins works , cloud management and cloud provisioning, etc. So, then it is also called as a software provisioning tool. YAML is nothing but a programming language that is used by Ansible and is inherited from python language. A YAML program can be called as a Ansible script which is having several lines of instruction followed by its features.
Working with Ansible YAML
We have two different nodes that are named as control node and managed node. Between them, control node is a machine which runs Ansible and there should be at least one control node whereas the managed node can be any device which is being managed by control node. By connecting all these nodes an Ansible works and there is a small program which can be written in YAML programming language.
We connect the nodes over SSH and they can be removed once they are no longer required.Previously applications and servers are maintained by the administrators, but the number of application deployments and their enhancements are increasing drastically so Ansible kind of tools came to picture to work with and make the administrator works simple.
To work with Ansible we should be aware of the following terms which are frequently used in Ansible.
They are as follows:
- Controller Machine: In this Ansible get installed as said above and is responsible for running the provisioning which we are monitoring.
- Inventory: It contains about all the servers which we are managing for the application and it is also called as an initialization file for Ansible.
- Module: Ansible having several numbers of different modules which are built in. We can also create our own custom modules as well. Module is nothing but a set of different tasks.
- Task: It is a single procedure or a thread which can be executed.
- Play: In simple words a play is provision which can be executed from start to end. In ansible a play can be execution of the playbook we can say.
- Playbook: It is an entry point where all the tasks are defined and executed in an order inside it. The play will be started from the top of provisioning process inside which are defined in YAML format.
- YAML: It is the programming language which is used in Ansible scripting. Every Ansible playbook will be written in YAML and the extension of the file is *.yml or *.yaml.
- Role: To organise all the playbooks in a pre-defined way or structured way we need a procedure and that is called a role in Ansible which facilitates the sharing and reusing the provisioning portions or parts.
- Facts: It can be defined as global variables in Ansible. These contains the information about the systems.
- Handlers: They can look after the service status changes. Ex. Start, stop and restart services, etc.
Lists and Dictionaries
YAML is easier and humans can read & write easily, we use it in Ansible.
YAML Syntax
A YAML file always starts with the header of three dashes “—” and ends with three dots “…” formally. So, these can indicate a developer or user that the start and stop points of the YAML scripts.
For example:
In the same way a dictionary is written in a simple “key: value” form as shown below:
Both the lists and dictionaries can also write in an abbreviated form as shown below:
We can find more information about the writing up of lists and dictionaries in the Ansible Docs which can be available by the Ansible original website. By combining all the lists, dictionaries, tasks, hosts, etc we can make a Ansible playbook written in YAML language. One of the important thing in Ansible script is it uses shell commands and issues them from a central location to perform.
Benefits of Ansible YAML
- It is simple to install Ansible and it is an open source.
- It is simple tool to use and the syntax of Ansible is more user friendly which can be understandable to a new user as well.
- It works as an agentless where we don’t worry about installing the agents in the client machines from where we are going to connect for the communication.
- As it has better and powerful features, it can allow a user to model even the most complex workflows in IT. With these capabilities of Ansible we can orchestrate the entire application environment regardless of deployment where we did it.
- It is so efficient as it does not require no extra software for our applications.
- It uses JSON to work around with its modules. So, it can be extensible with the modules which are written in YAML programming.
- It is also used in provisioning of an application.
- It is mainly a configuration management tool so where it can maintain the consistency of a product performance. It is possible by Ansible because it records and updates the detailed information of the both hardware and software.
- It is more of an application deployment tool where it defines the application with the Ansible itself and uses Ansible Tower to manage the deployments.
- A security policy in Ansible can also be integrated into another automated process. It is good enough in terms of security and compliance also.
Conclusion
There are so many other open source and non-open source configuration management tools available in the market listed Puppet, Chef, SaltStack, etc. But why this is ahead of all these? Because, Ansible is not only limited to Configuration Management like other tools. It can also be used in many other ways as Provisioning, Application Deployment, Security & Compliance and orchestration as well. And coming YAML, it is a programming language with simple and structured syntax in a step by step procedure of multiple defined tasks. This Ansible YAML is playing vital role in DevOps culture which is an ongoing IT trend in an Application or a Project end to end to process life cycle.
Recommended Articles
This is a guide to Ansible YAML. Here we discuss the introduction, working, list and dictionaries, and benefits. You may also have a look at the following articles to learn more –