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 - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
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
-
-
-
(Locked)
Installing collections2m 20s
-
Construct a simple playbook4m 19s
-
(Locked)
Using variables5m 7s
-
(Locked)
Using loops2m 45s
-
(Locked)
Adding conditionals4m 57s
-
(Locked)
Utilizing blocks3m 49s
-
(Locked)
Exploring templates4m 29s
-
(Locked)
Discovering handlers2m 23s
-
(Locked)
Using tags2m 53s
-
(Locked)
Testing plays with check mode2m 15s
-
(Locked)
Conditional failure with assert2m 20s
-
(Locked)
Failure and change control2m 32s
-
(Locked)
Nesting loops3m 29s
-
(Locked)
Creating dynamic inventory files3m 7s
-
(Locked)
Challenge: Create a complex playbook1m 17s
-
Solution: Verify the complex playbook2m 52s
-
(Locked)
-
-
-
-