Ansible Basics 05: Playbooks

Ansible playbooks are the core components of Ansible. Playbooks are written in YAML format and describe a set of tasks that need to be executed on the managed systems. A playbook consists of one or more plays, and each play defines a set of tasks to be performed on a group of hosts. Tasks are the individual actions or commands that Ansible should execute, such as installing packages, copying files, or restarting services. Tasks call out to the programmed code units called modules.

Continue reading “Ansible Basics 05: Playbooks”

How to implement Ansible blocks in our code to group and manage tasks together?

There are some limitations of using YAML instead of a scripting language or a DSL, but the developers of Ansible thought about the issue, and they integrated some cool, more advanced features into the tool. We can use blocks collecting and handling tasks together Let’s investigate this feature a bit more!

Continue reading “How to implement Ansible blocks in our code to group and manage tasks together?”

Conditional statements – making decisions in Ansible code

In a playbook or in a role sometimes we want to run different tasks based on different conditions. In most cases it depends on a fact (detail about the managed host) or some data collected during the playbook run. Ansible conditionals are there to make it possible to run different tasks based on different conditions, or skip executing tasks entirely.

Continue reading “Conditional statements – making decisions in Ansible code”

Creating an Ansible role from a playbook: modular, reusable code

After we ran ad-hoc commands and created a monolith playbook, we will increase our level of automation. We will separate our code much better with introducing modular, reusable file structures called roles. Ansible roles will load variables, handlers and tasks automatically for us based on a defined directory and file structure.

Continue reading “Creating an Ansible role from a playbook: modular, reusable code”