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.
Conditional failure with assert - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Conditional failure with assert
- [Instructor] On occasion, it can be useful to place some checks in a playbook. Often it can be useful to have a playbook fail if certain conditions aren't met. Common conditions would be if a system doesn't have enough RAM or perhaps not enough hard drive space. This is done with the assert module. I'm going to start with a playbook named assert.yml. Notice at the top that I've commented out gather_facts false, so my playbook will reach out to my host and gather my variablized information. My first task here is just dumping out how much RAM my system has. The ansible_memtotal_mb variable is populated with gather_facts at run. I'll create an assert statement by checking if my system has more than a gig of RAM. So I'll start with a name assert if RAM is at least one gigabyte. Now the assert module, ansible.builtin.assert. Now for the assert parameters that do the work, that ansible_memtotal megabyte is greater than 1000. Now we'll create a message to display if the assert fails…
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)
-
-
-
-