cancel
Showing results for 
Search instead for 
Did you mean: 
KentPerrier
Mission Specialist
Mission Specialist
  • 1,268 Views

chapter 4 review exercise: logic error in objective 2

Jump to solution

In objective 2 it says "This task should only be executed when the remote system does not meet the following minimum requirements" and it lists 2 requirements: the system has at least the amount of ram specified in the min_ram_mb varible and it is running RHEL.

The documented solution has 3 errors (or at the very least very misleading):

  1. it is using OR instead of AND for the conditions. As instructed, the system has to meet both requirements, which would be an AND condition, nor an or
  2. the system as at least the amount of ram (in mb). The test in the documented solution shows it is testing that ansible_facts['memtotal_mb'] IS LESS THAN min_ram_mb. The test should be >=
  3. ansible_facts['distribution'] should == "RedHat"

In the documented solution the system could not have the necessary memory (less than 256 mb of ram, failing the first check) but be running ubuntu (passing the second) and the playbook would pass it. Or the other way around having enough memory but running RedHat.

IMO, the solution is wrong, but I might be reading it wrong. I can't find anything in the ansible docs about conditionals that would say I am wrong here. I'd love some input on this.

1 Solution

Accepted Solutions
Travis
Moderator
Moderator
  • 1,264 Views

@KentPerrier -

So I believe this is written to where it is a little hard to understand, but we want it to fail FAST, so we are using some of the Microsoft GPO type logic of multiple sets of negatives here. These types of tests always make you think. So we aren't actually wanting this task to run because this is a FAILURE. However, we are wanting things to fail fast before we change any work to the system.

So you are correct in that normally we want the playbook and tasks to run when we meet both conditions meaning the system must be running RHEL and must have at least 256MB RAM. However, in this instance, we want the failure to happen and the tasks to run when the conditions aren't met and it also becomes an "OR" because if either one of the conditions isn't met, then the playbook should fail and no tasks are run.

So what you are doing here is checking ... is the system running Red Hat, if not, then the condition evaluates to true and the OR makes it fail at this task. The other thing you are checking is the system less than 256MB RAM, so if that is true (regardless of whether or not it runs RHEL) you want it to fail.

So this first task takes the facts from the system, evaluates what is happening and fails immediatey without executing the rest of the playbook. So what they are doing in the solution is making sure that no other tasks are run.

So you need to step back and read the bullet points separately and think of what is being asked ...

  • System must have a minimum amount of RAM
  • System must be running RHEL

Both conditions must be TRUE in order to actually run tasks and configure the system. If either one doesn't meet the requirements the playbook should fail. So that tells you it should be an "OR" for the conditional. Furthermore, since we are using a FAIL module, we want to evaluate based on "opposites" so not running Red Hat and less than the minimum RAM would trigger a failure.

Again, the wording here and even this explanation is hard to follow, but keep in mind the end goal of what we are wanting and in DevOps we want to fail fast.

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training

View solution in original post

5 Replies
Travis
Moderator
Moderator
  • 1,265 Views

@KentPerrier -

So I believe this is written to where it is a little hard to understand, but we want it to fail FAST, so we are using some of the Microsoft GPO type logic of multiple sets of negatives here. These types of tests always make you think. So we aren't actually wanting this task to run because this is a FAILURE. However, we are wanting things to fail fast before we change any work to the system.

So you are correct in that normally we want the playbook and tasks to run when we meet both conditions meaning the system must be running RHEL and must have at least 256MB RAM. However, in this instance, we want the failure to happen and the tasks to run when the conditions aren't met and it also becomes an "OR" because if either one of the conditions isn't met, then the playbook should fail and no tasks are run.

So what you are doing here is checking ... is the system running Red Hat, if not, then the condition evaluates to true and the OR makes it fail at this task. The other thing you are checking is the system less than 256MB RAM, so if that is true (regardless of whether or not it runs RHEL) you want it to fail.

So this first task takes the facts from the system, evaluates what is happening and fails immediatey without executing the rest of the playbook. So what they are doing in the solution is making sure that no other tasks are run.

So you need to step back and read the bullet points separately and think of what is being asked ...

  • System must have a minimum amount of RAM
  • System must be running RHEL

Both conditions must be TRUE in order to actually run tasks and configure the system. If either one doesn't meet the requirements the playbook should fail. So that tells you it should be an "OR" for the conditional. Furthermore, since we are using a FAIL module, we want to evaluate based on "opposites" so not running Red Hat and less than the minimum RAM would trigger a failure.

Again, the wording here and even this explanation is hard to follow, but keep in mind the end goal of what we are wanting and in DevOps we want to fail fast.

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
gmichae
Mission Specialist
Mission Specialist
  • 1,134 Views
It's Boolean logic to put it more simply:
Negated AND gate:
Option1 Option 2 Result
(negative(true)) (negative(true)) False
(negative(false)) (negative(true)) False
(negative(true)) (negative(false)) False
(negative(false)) (negative(false)) True



Greg Michael
Spec. IS Infrastructure Platforms-Automation
Greg.Michael@cpkcr.com
O 612-607-1588
C 612-503-7117
120 S. 6th St.
Minneapolis, MN 55401
celeritas, sumptus, qualitas - carpere 2 <>
KentPerrier
Mission Specialist
Mission Specialist
  • 1,111 Views

"So I believe this is written to where it is a little hard to understand, but we want it to fail FAST, so we are using some of the Microsoft GPO type logic of multiple sets of negatives here."

 

Old time linux sys admin here, I have no idea what Microsoft GPO type logic is. Perhaps, if this is needed it should be included in the class and not expect people to pull this out of the air.

Travis
Moderator
Moderator
  • 1,094 Views

The Microsoft GPO Logic was a JOKE!!!

See above @gmichae post on how things evaluate and then look at the longer explanation I wrote and really think about what is happening. There is nothing to pull out of the air. Look at what it is asking you to do and figure out how to test and you will see that the solution is actually correct.

If you take Linux out of this and say I'm a driving instructor and I tell you that you must drive backwards less than 45 MPH and you must be in reverse to do it ...

The condition would fail if either one or both is evaluated as true.

speed > 45 MPH

gear != REVERSE

So if you think of how the condition was presented in the book, if it has less RAM or if it isn't Red Hat or if it has less RAM and isn't Red Hat it fails.

 

Travis Michette, RHCA XIII
https://rhtapps.redhat.com/verify?certId=111-134-086
SENIOR TECHNICAL INSTRUCTOR / CERTIFIED INSTRUCTOR AND EXAMINER
Red Hat Certification + Training
  • 191 Views

My explanation: 

You are testing for any failure. You have two items and if any does not meet the criteria (ANY), you have a failure. So it does not matter if you have less memory OR wrong operating system, both result into a failure.

It would be different if you tested for positive outcome, then you would look for AND.

Join the discussion
You must log in to join this conversation.