From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Utilizing blocks

Utilizing blocks

- [Instructor] Blocks add some efficiencies and also have a few features you can't really find anywhere else in Ansible. To be honest, I'm usually using them to group tasks together that share a single conditional. In this demo, I'll be installing the Nginx web server, then, I'll start and enable its service. I've got this playbook set up so that it can do it either on a Rocky host or Ubuntu host, which differ on the modules they use for the install. Just as a note here that I could use the ansible.builtin.package module, and it would install Nginx on either system, despite their differences. But, for the sake of this demo, I'm using the DNF and APT modules. I started by pasting in the play section. Note here that I commented out gather_facts: false. That's because I want to check the distribution version in a conditional below. I'll now start my first block by naming it, as always. - name: Block for Rocky hosts. After that, I'll add a conditional that will apply to the whole block…

Contents