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):
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.
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 ...
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.
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 ...
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.
"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.
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.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.