EX294 Red Hat Certified Engineer RHCE – Ansible Plays and Playbooks, Conditional Execution Part 5

  • By
  • January 19, 2023
0 Comment

13. Task: Creating Logical Volume using Conditional execution and Error handling

In this lecture, we learn how we can create logical volumes using when condition in conditional playbook execution. Here is task description create a playbook logvolt YML to create logical volume with name LVM on May 8, nodes meeting below conditions create logical volume of size 800 MB if Volume Group VGROUP has sufficient free space greater than 800 MB. We know in previous task, we created Volume Group with name vgrup on Web Service Node and prode one node. It’s not created on prode two node which is m host two. Create logical volume of size 500 MAB if Volume Group has free space less than 800 MAB. We know this is a case of probe one host. But I will say in case of M host one where we created Volume Group of size 600 MAB, message volume Group does not exist should be displayed if Volume Group is not created one node.

So we need to configure error handling for M host two where we did not create this Volume Group. Here we have playbook contents we will be using for this task, we’ll set target as all managed nodes here become must be set to true because we need per will the escalation for this task. Also, we must set gather underscore Facts to true because we need to use ancient Facts variable for conditional checks here in Tasks section, our tasks are defined. First task is to create logical volume of size 800 mabuytes. Here, we’ll use Elvol Module Logical Volume Module. We’ll check ancient documentation for this module before starting this task. But this is easy to understand. Here, using VG directive will set Volume Group we will be using for logical volume.

So in our case, it’s V group. Then using LV will specify name of logical volume we need to create which is LVM. In our case, using Size directive will specify size 800 m so it means 800 MAB. In case you need to specify size in Gibby bytes, replace and with G. Now, according to task requirement, logical volume of size 800 megabytes should be created on remote nodes where VGROUP exists and VGROUP has free space more than 800 mabibytes. For this, we are using these two when conditions using logical and between them. Here in this first condition, we are checking if this VGROUP dictionary variable is present under this dictionary. So here by using this expression, we are referring this nested dictionary variable. So when we create Volume Group one dictionary with name same that a Volume Group is created under this dictionary. So we can use this condition to check if logical volume is created one node or node. Here important is you must enclose VGROUP inside single quotation marks. Also, we must enclose both these conditions inside double quotation marks.

Then here coming to next condition here, by using this expression, we are referring to free size available in Volume Group v group. This must be greater than zero point 79. This value must be enclosed in single quotation marks. So why I’m using zero point 79 here? Because by default and civil facts are displayed in Gibby bytes. So here I am converting 800 MAB into Gibby bytes, which is roughly equal to this value. Now, based on these two conditions logical Volume of size 800 MB will be created on manage nodes where Volume Group VGROUP is created and free size on the Volume Group is greater than 800 MB. We know this is a case of web servers nodes. The next task creating logical volume of size 500 MAB here everything is same. We need to use size as 500 MAB and here in the Win condition we need to change this to less than if free space in Volume Group is less than 800 MB. In that case, create logical volume of size 500 MAB, which is in case of prode one node M host one the last task to display message when volume group does not exist which in our case is m host.

Two where we did not create this volume group we’ll use debug material and using famous MSG directive will display wall group does not exist when VGROUP dictionary variable. Note in this dictionary VGS again you must enclose VGROUP in single quotation marks and complete statement in double quotation marks. This is important. Now let’s move to the ansible Control Node and start doing this task. Now we are on ansible Control node and I am logged in as ansible user here on this path we need to create our playbook. Before we create playbook, I will display documentation for Elvo module. Here we have description this module creates, removes or resizes logical volumes. Here we’ll discuss important parameters or directives we need to know for this task force we can use when we need to remove or shrink some logical volume.

We don’t need this for this task LV the name of logical volume we will use this in our task to specify name of logical volume, then Size the size of logical volume which can be specified in different units. We are using M for Mabibuytes then state which is by default present. However, I always CSU to mention it in the playbook to make sure we don’t miss anything. Then this is important the Volume Group name which we need to use for this logical volume then here in the end we have some examples. So even if you don’t specify M with size, by default this will be taken as Mabibuytes.

Now I will quit this. I will clear the screen. Now I will display Ancill facts for M host One just to understand how we can form expressions for different conditions. For this, I will execute ansible ad hoc command using Setup module. Here we must use Dash Become so that all facts will be gathered. In case you don’t use Dash Become, you will not find information about logical volumes and Volume grows. So make sure in case privilege escalation is disabled. In config file you must use dash become. Here I will save the output in some file with name LVM fax because this will be easy to analyze. Now we have facts stored. Now I will open this file. In this file I will search for ancievel underscore LVM. Here we have this dictionary. Under this dictionary you can see next level dictionary variable VGS. And under this dictionary variable we have this dictionary variable V group which is our volume group.

So this is present. Because volume group is created on this node. So by using first expression we are checking if we group variable is present under this dictionary variable. To refer to this dictionary variable, we are using expression and Sibble underscore facts then LVM then VGS. We know we need to use bracket or dot notation here. Now further we can check more details about this volume group free underscore G displays free size available on this volume group and size underscore G displays total size of volume group. In our case, this is not used at all. So that’s why free size and total size of volume group are same. So in second condition we are referring to this key using expression we know how we can make expression. Now I will quit from here.

Now what we’ll do will again gather facts. But this time for M host two where we did not create volume growth. I just wanted to show you what is there under LVM dictionary. Again we need to display and here I will search for ansible underscore LVM. Here we can see there is nothing under VGS. Because volume group is not created on this host. So for this host will display message volgroup does not exist based on condition VGROUP not in then we need to provide expression refer to this dictionary variable. Now we will quit. I will clear the screen. Now we’ll create our playbook with name logvol dot YML we’ll set target to all become must be set to true. Gather facts must be set to true. Although this is deferred behavior I’m using here then here we’ll define our task in tasks section.

First task is to create logical volume of size 800 MAB. I will provide description here. Creating logical volume of size 800 MAB. Here we know we need to use LVL module. Using VG will specify volume group to be used which is VGROUP. In our case, using LV will specify name of logical volume to be created which is LVM. As per task requirement the size here is important. We need to create logical volume of size 800 MAB. State must be set to present. This is default. However, I will prefer to mention it here. Now here we need to specify two when conditions. We know we can specify logical and conditions as list items. I’m using same here. First condition is we group in ansible facts then LVM, then VGS. Here we are referring to this nested dictionary variable. Here we are checking if we group dictionary variable is present under this dictionary then here important is we must enclose this statement in double quotation marks. Don’t forget this. Also don’t forget to enclose VGROUP in single quotation marks. Then here we specify our next condition. We know which expression to use. Here we can use this expression to refer free size available in Vgrop.

Now here I will use greater than symbol and here I will specify value zero point 79 enclosed in single quotation marks. So based on these two conditions, logical volume of size 800 MAB will be created on remote nodes where volume group is created and free size available on volume Group is greater than 800 MAB. Now moving to the next task. Next task we need to define to create logical volume of size 500 MAB. Here I will provide description creating logical volume of size 500 mabides we know we need to use elvol module using VG will specify volume group name using LV will specify logical volume name size in this case will be 500 m I will specify state as present.

Again, conditions are important. First condition is to check if volume group is created on node or note now here we need to specify second condition to check if free space available on volume group is less than zero point 79gb we know which expression to use here. So here we need to use this expression to refer to free size available on volume group. Now here we’ll use less than and here I will provide value zero dot 79 enclosed in single quotation marks. Now based on these two conditions, logical volume of size 500 megabytes will be created on nodes where free available size on volume Group is less than 0. 79gb we know this is in case of m host one. Now moving to next task to display message if volume group does not exist here we need to provide description displaying message when volume Group does not exist here we know we need to use debug module and using MSG will display our message volt group does not exist, we need to enclose this in double quotation marks.

And here again we need to specify condition. Here we need to specify only one condition vgrup not in here we need to use not in then here we need to provide or specify expression referring to VGS. So this is the expression. We must enclose this statement in double quotation marks this is all we need to do for this task. Three dots indicating end of YAML document. Now before I save and quit, I will just go over the contents of this playbook just to make sure everything is fine and we did not miss anything. Everything seems okay till now? Yes, everything is okay seems okay. Now we’ll perform syntax check everything is okay. Now we’ll execute this playbook. So here we have tasks gathering facts in progress, creating logical volume of size 800 MB, and it has been created on web servers, nodes. And in this case, task two is executed only on m host one, because m host one has volume group of size 600 MAB, which is less than 800 MAB. So here, logical volume of size 500 MAB is created as per requirement. And here we have message for m host two. Volume group does not exist.

So this is as expected. Now I will clear the screen null verify using ansible ad hoc command ansible all. And here I will execute command LVS, which is used to display logical volumes. Or we can use LV display as well. Here you must use become. So here we have output O Nam, host one we see logical volume of name LVM and size 500 MAB. And on Mhost three and four we have size 800 MAB. We don’t have any output for Mhost two, which is as expected. This is over.

14. Task: Creating Logical Volume Using All Free Space on Volume group

Hello, welcome to this lecture. In this lecture we will again create logical volume using all remaining space on volume group WeGroup here is task description create a playbook volume to create logical volume with name wall on remote nodes meeting conditions create logical volume to use or manning size on volume group Vgrop. So here we’ll use Ole size available on Vgrop volume group message VG does not exist should be displayed if volume group is not created on node. Here we have playbook contents again we’ll set target as all remote nodes become must be set to true or yes for pervillage escalation gather underscore facts must be set to true because we need to use ancible facts variable for conditional checks. Here in the tasks section will define our two tasks where our two tasks are defined first task is creating logical volume.

We know here we need to use LVO module again using VG directive will specify name of volume group to be used which is VGROUP in this case as well using LV will specify logical volume name to be created which is wall. So here size is important. So here task requirement is we must use or remaining space on Vgrop. For this we’ll use 100% free. We know we can use same with Lvcreate command line as well same we are using here then here this condition is important. Again we need to check if V group is present under this dictionary variable only then create logical volume then in next task displaying message we know we need to use debug module using MSG will display message VG does not exist when we group note in this dictionary variable.

But I would say when Vroup dictionary variable is not present under this nested dictionary variable we know this is a case of M host two. This is all about description. Now let’s move to the ensable control node and start doing this task. Now we are on ansible control node and I am logged in as ansible user. Here we need to create our playbook. But before we proceed further I will again display documentation for Elvol. Here we need to check size directive. Here we can see we can define size by defining percentage of free extents to be used. In our case we are using 100%. Now we’ll move to the examples. So here you can see similar example size is 100% free create a logical volume using or many space in the volume group. Now I will quit. I will clear the screen. Here we’ll create our playbook with name volume dot YML we’ll set target as all become must be true. I will set gather facts to true. Then here we need to define our task creating logical volume. We know we need to use elvol module using VG we specify volume group to be used using LV we specify name of logical volume to be created here size we need to specify 100% free.

I will specify state as well. Although this is default now here when condition when VGROUP variable is present under VGS dictionary variable VGROUP in then here we need to provide or we need to refer to dictionary variable VGS. This is all we need to do then moving to the next task displaying message here we know we need to use debug module using MSG will display message VG does not exist again here we need to specify when condition when WeGroup note in and here again we need to provide or we need to refer to VGS dictionary variable here. I forgot one thing. We must enclose this in double quotation marks. Don’t forget this. Also this statement this is all we need to do for this task. I will just go through contents of this playbook to make sure everything is fine. Everything seems okay. We’ll save and quit before execution. We’ll perform syntax check. No errors. Now we’ll execute this playbook. Gathering facts. Facts are being gathered creating logical volume. So it has been created on three nodes m host two is skipped. Because we know VGROUP does not exist on this host. For this we have this message again we’ll use ansible ad hook command.

We’ll execute LVS and here we must use dash dash become here we have output. Here we can see one more logical volume on the list using over many size of WeGroup now I will display VGS. So here we can see free size on volume group is zero because we used all free space for the logical volume wall. This is all about destroying.

15. Task: Mounting Logical Volume persistently Using Conditional Playbook Execution

Hello, welcome to this lecture. In this lecture we’ll learn how we can mount logical volumes. We’ll use when condition to check if logical volume is existing on the system or node. You might need this on the exam. Here is task description create a playbook mount underscore volts to mount logical volume wall created in previous task. Create file system XFS on volume use mount pointers forward slash volume LVM and mount should be persistent. So it means we need to mount volume through fstab file. We know we can do this by setting state to mounted with mount module. Here we have playbook contents. We’ll set hosts to all become must be set to true because we need root privileges. Gather underscore facts must be set to true because we need to use Ancill facts variables for conditional checks. Here we have tasks section with two tasks defined under.

This first task is creating file system. We know we need to use file system module by using dev, we’ll provide path of device which is forward slash devgroup wall. Then by using FS type, we’ll specify file system which is XFS as per task requirement. Here I’m using when condition when wall in ensible facts LVM LVS so as we understood already, when we create volume group one dictionary variable is created under VGS dictionary. So in case of logical volumes, dictionary variable with same name as that of logical volume will be created under this dictionary variable LVS. We need to use this expression to refer this nested variable. I’ll show you when we move to the system. The next task is mounting logical volume. We need to use mount module by using SRC will specify device to be mounted. Then path where we need to mount this device.

In case this path does not exist, same will be created FS type. This is mandatory with state set to mounted. We’ll set FS type to XFS. The state must be set to mounted so that volume will be mounted persistently through FS tab. We already discussed about state in mount module. Again, I’m using same one condition here. So we could do same task by setting target as web servers and prode one nodes. In that case, we could remove these two when conditions. But on the exam you might not know on which nodes logical volume is present or node. Then these conditions are more useful or very useful. Now let’s move to the ancient control node and start doing this task. Now we are on ansible control node and I’m logged in as ansible user. On this path, we need to create our playbook. But before we create playbook, I will display ansible facts for mhostone. Just to understand the expressions we will be using in this task ansible m host one we know we need to use setup module.

We must use become to display all facts. I will save the output to some file. It’s completed. Now we’ll open this file and I will search for Msible underscore LVM. Here we have this dictionary variable. Under this we can see LVS, and under LVS we can see our logical volumes. So here in our case, we need to check if this dictionary variable with name vol is present under this LVS dictionary. So we know which expression to use. ncible underscore facts, then LVM. Then LVS. So this will be the complete expression. Of course we need to use brackets and commas as well. Now I will quit this. Then here we’ll create our playbook with name mount underscore wall YML we’ll set target to all become must be set to true. We know why gather facts. I will set this true. Then here we’ll define our task. First task is creating file system. We know here we need to use file system module.

We need to specify dev device which is forward slash dev forward slash VGROUP then forward slash wall FS type XFS as per task requirement. Then here we need to specify when condition when wall. This must be enclosed in single quotation marks. Then here we need to provide expression to refer LVS dictionary variable. This is all we need. We must enclose this in double quotation marks. Don’t forget this. Then here we’ll define our next arc mounting logical volume we need to use mount module. Here we’ll use SRC to specify device but I will say file system then path where we need to mount this which is forward. Slash volume LVM we know this path does not exist same will be created FS type we must specify this which is XFS state mounted we know when state is set to mounted device will be mounted and entry will be created in SS tab file for persistent mount.

This is all we need to do. But here we must specify when condition, when volley and here we need to refer to the facts variable LVS. This is all we need to do. We must enclose this in double quotation marks. Now I will save and quit before saving. I will just go over the contents of this playbook to make sure we did not miss any coma or we did not make any other mistake. Everything seems okay now I’ll verify syntax of this playbook all seems OK. We’ll execute this playbook. We have task gathering facts in progress creating file system so here Mhost two is skipped as expected then mounting logical volume so it has been mounted for three nodes m host one which is prod one node and M host three and four which are web servers node so everything seems okay I will create the screen. Now we’ll verify using ensible ad hoc command I will display Bloke devices.

Here we can see our logical volume is mounted on this mount point same for M host four in case of two, we don’t have this logical volume. Now I will clear the screen. Now I will display Fava file. Here we must use become flagged because we need root privileges to display this file. So here we can see anti four, our file system wall. So this is M host four. This is M host three. We don’t have this entry on M host two, as expected. And we have this entry one, M host one. So we have everything in place. This is all about this task here. We also conclude this section. In next section we’ll learn how we can use template module with Ginger two templating files to deploy different templates. We’ll also learn how we can use ansible Bolt to protect sample.

Comments
* The most recent comment are at the top

Interesting posts

Impact of AI and Machine Learning on IT Certifications: How AI is influencing IT Certification Courses and Exams

The tech world is like a never-ending game of upgrades, and IT certifications are no exception. With Artificial Intelligence (AI) and Machine Learning (ML) taking over everything these days, it’s no surprise they are shaking things up in the world of IT training. As these technologies keep evolving, they are seriously influencing IT certifications, changing… Read More »

Blockchain Technology Certifications: Exploring Certifications For Blockchain Technology And Their Relevance In Various Industries Beyond Just Cryptocurrency

Greetings! So, you’re curious about blockchain technology and wondering if diving into certifications is worth your while? Well, you’ve come to the right place! Blockchain is not just the backbone of cryptocurrency; it’s a revolutionary technology that’s making waves across various industries, from finance to healthcare and beyond. Let’s unpack the world of blockchain certifications… Read More »

Everything ENNA: Cisco’s New Network Assurance Specialist Certification

The landscape of networking is constantly evolving, driven by rapid technological advancements and growing business demands. For IT professionals, staying ahead in this dynamic environment requires an ongoing commitment to developing and refining their skills. Recognizing the critical need for specialized expertise in network assurance, Cisco has introduced the Cisco Enterprise Network Assurance (ENNA) v1.0… Read More »

Best Networking Certifications to Earn in 2024

The internet is a wondrous invention that connects us to information and entertainment at lightning speed, except when it doesn’t. Honestly, grappling with network slowdowns and untangling those troubleshooting puzzles can drive just about anyone to the brink of frustration. But what if you could become the master of your own digital destiny? Enter the… Read More »

Navigating Vendor-Neutral vs Vendor-Specific Certifications: In-depth Analysis Of The Pros And Cons, With Guidance On Choosing The Right Type For Your Career Goals

Hey, tech folks! Today, we’re slicing through the fog around a classic dilemma in the IT certification world: vendor-neutral vs vendor-specific certifications. Whether you’re a fresh-faced newbie or a seasoned geek, picking the right cert can feel like trying to choose your favorite ice cream flavor at a new parlor – exciting but kinda overwhelming.… Read More »

Achieving Your ISO Certification Made Simple

So, you’ve decided to step up your game and snag that ISO certification, huh? Good on you! Whether it’s to polish your company’s reputation, meet supplier requirements, or enhance operational efficiency, getting ISO certified is like telling the world, “Hey, we really know what we’re doing!” But, like with any worthwhile endeavor, the road to… Read More »

img