EX294 Red Hat Certified Engineer RHCE – Using Ansible Modules For System Administration Tasks Part 5

  • By
  • January 20, 2023
0 Comment

12. Task: Creating Partitions using Playbook

Hello. Welcome to this lecture. In this lecture we’ll learn how we can create partitions or manage partitions using ansible playbooks. Here is task description. Create a playbook parter dot YML. To create extended partition on all manage nodes, use our remaining space for extended partition we’ll use or remaining free space on the disk for the standard partition which will act as container for logical partitions. We will be creating or we will need to create further create one. Logical partition of size 200 MB on all the remote nodes or manage nodes. Here are the contents of playbook we are going to use for this task.

So here target is all remote nodes because we need to create extended partition as well as logical partition on all the managed nodes become must be set to true or yes, because this is system administration task we need to set gather underscore facts to true. This is important for this. Task because we will be using facts during this task so here in the tasks section in this first section using parted module will register information about disk using register keyword I will explain about this during the task and I will also explain how this works.

We’ll use this info in the following two tasks. Again, it will be more clear during the task. In the second task, we are defining how to create extended partition on the managed. Nodes. So here again, we need to use parted module. Using device directive we’ll specify disk which is SDA. Using number, we need to provide number of partition we are going to create. So in our case we already have. Three partitions created on disk on all the managed nodes. So we will be creating fourth partition as extended partition. Part underscore type will set this to extended because we are going to create extended partition. So here part underscore start. So this is important. So normally when we use fdisc to create partitions, fdisc by default takes first free sector as starting point for new partition we are going to create.

But here in case of partnered in the playbook we need to tell the parted starting location of partition we are going to create for this we are using this expression and here we are using info of the device where yesterday using this task using this expression will calculate and location of the disk which is used by already existing partitions I will explain this during the task then using next task we will be creating logical partition again we need to use parted module we will use same directives differences. Partition number is five because after creation of extended partition, next partition number would be five part underscore type we need to set to logical because we are going to create logical partition again, we need to tell parthood starting a location of partition. We’ll use this expression and here important is we must tell parthood where partition should end.

Because here we need to create partition of size 200. MAB’s. In this task we did not use part underscore end because task requirement is we need to use all the remaining space for extended partition. Part underscore end is by default end of the desk. So we can omit this from this task. But here in this task we must define part underscore end to define end of the desk. Difference is 200 MAB between these two values. If you do simple mathematical calculations. But I will explain this during the task state must be present in both tasks because we need to create partition. Now let’s move to the system and start doing this task. Now we are on ansible control node and I am logged in as ansible user. First of all I will display documentation four parted module.

So here we can get all the information about this module. This module allows configuring bloke device partitions using parted command line tool. So here we’ll discuss important directives we need to use for this task device. The bloke device where to operate in our case SDA disk. Then using flags directive we can set flag on the partition. For example, in case you need to use some partition for logical volumes we can set flag LVM. But we don’t need this directive in this task the number this is a partition number. Part underscore end and part underscore start directives are important here. So here is definition of part underscore end where the partition will end as offset from the beginning of desk. That is the distance from the start of desk. So default is 100%. That’s why we did not define part underscore end in the task where we defined how to create extended partition. Because by default it will be end of desk because we need to use or maining free space of the desk.

Here we just need to define starting location where the partition should start by default and will be end of the desk. But we can always specify absolute values like 10GB offset from the beginning of the desk. We can also specify percentage then part underscore start where the partition will start as offset from beginning of desk. That is the distance from start of the desk. The distance can be specified with all the units supported by parted. Again we can use absolute values. For example 10GB. So partition should start 10GB offset from beginning of desk. We can also use percentage value. In our task we are using variable to define part underscore start. If you know which is the first location available, you can directly specify absolute value as starting location of partition. Then part underscore type which can be extended logical. Primary by default is primary.

So in our task first we need to create extended partition, then we’ll create logical partition. After extended partition will be created. So in the playbook one thing is very important. Tasks are always executed in sequence. It means first defined task will be always executed first, then the next task, the next state. By default. This is info. But to create the partition we must set this to present. To delete the partition we must set this to absent. So in the first task where we are storing the information about disk, we are using default info. We are just storing the info about disk. To use the info in the subsequent tasks. We can use unit to specify unit we need to or we want to deal with. So here we have some examples for the playbooks. Just go through them.

So here I would like to tell you about Flags. In this case, flags is set to LVM enclosed in the scare bracket. This means this partition will be used for logical volumes. So here is task which we used to register info about the Desk. This is exactly same task we used in our playbook using Parted Module. We specified device and unit. You can specify these directives in one line. Or you can even specify like we do normally. Then we need to use register keyword to register the information about this in this variable. Then later on we can use this variable in the subsequent tasks for which we are going to do in our task. So now I will quit. I will clear the screen. Now before we start creating partitions, I will explain how yesterday keyword is used to store info about the Desk. Here I will create playbook with name test dot YML. We know three dashes on the top.

We can specify any host because we just need to verify how it works. I’m using amhost one become must be set to true. Because we need to gather facts which can be gathered only as root user. For example, info about desk. Then gather underscore facts must be set to True. Now here I will define one task in the tasks section. Here we’ll provide some description register info. We know we need to use parted module device SDA we need to provide complete path. Then here we can specify or we need to specify unit we need to deal with. So we are taking units as mabi bytes. Then state which is Info by default. Now here we will be using keyword register. So make sure level of indentation here is same as that of module. And here we need to tell the variable name. Or we need to define variable name. For example SG underscore Info. Now what we’ll do, we’ll define one more task to display this variable using debug module. Displaying variable. Here we’ll use debug module using MSG will specify variable to be displayed. We know this expression sta underscore Info. This is the variable where information is registered about the Desk. I will save and quit. I would like to verify syntax before execution. Everything is fine. Now we’ll execute this playbook.

It’s taking some time. So here we have information about the disk. So in this way we can store information about disk in a variable. So here I displayed this variable, just to show you which information is contained in this variable. So here what we need for this task. I will explain that. Now we know we have three partitions number one, number two, number three. This is size four. This partition. This is size four partition number two. And this is size four. Our boot partition, which is 300 mabides. We also know the units in which size is displayed. So here important is where partition begins and where it ends. So we are interested in where the last partition ends. So it means which is the last location of the disk used. So this is the last location, 22,829 MAB. So now to create extended partition, we can do two things. We can directly specify value. For example, 22,830 MAB starting location of partition. We cannot use the same value.

We must leave some space between the end of last partition and starting off next partition. So in this case, for example, we’ll use 22,830 mebts as the starting location of extended partition. This will work perfectly fine, but instead we are using variable. Now I will clear the screen. And here I will just give one more example. Instead of parted, I will use command module. I will remove all these lines. And here I will specify some command. For example cat UTC hostname to display hostname file on the ammost one, I will just change this to Info. Again I will execute Playbook. So here is standard output. So these are the contents of this file. So if there will be error, it will be displayed in this line. So here you see standard output, or I would say STD out and STD out underscore lines. So here under this you will see standard output in different lines. But here you will see standard output in one line. If output is long file same for standard error. This is how we can use register to register the output of some command. Now again I will clear the screen.

Now we’ll start writing our playbook. We need to use playbook name as parted. Three dashes on the top target is all become need to set to true. Gather underscore facts must be set to true. This is important for this task. Then in the Tasks section we know we’ll define first task. To read disk info, we need to use parted module device SDA. We need to provide complete path. The next unit we want to deal with mabi bytese state. We’ll use Info, which is by default. Here we’ll use register keyword. So here you should keep in mind level of indentation for yesterday and module name are same. And here we’ll specify variable name. I will use SDA info. Now, before moving further to write tasks for creating partitions, I will tell how we can form expression. Here I will use debug module to display this info. Then we’ll access and location of last partition. I’m doing this just to explain how we can access that. But on the exam you must know already which expression you should use.

For this, I will use some description. Here we know we need to use debug module. And here using Ginger, two template for variable will access this variable. We already did this. Now I will execute this playbook. We know what will be the outcome. So here we have output for all the managed nodes. So I will take the example of any one node. So here we need to access this end, or we’ll use end key to access this value. Here we see partition is named list variable containing further dictionary items. So this is the first item, this is the second item and this is the third item. We need to access third item. Then further in this dictionary we’ll access this key. Now, first of all, I will access complete partitions variable. We know what we need to do, I will just modify this and we’ll add partitions here. Or we can do it other way as well. Using bracket notations, I will save, I will execute playbook again, it’s taking some time. Now we have limited output. This output is only about partitions. So here this symbol scare bracket indicates list. So there are three list items which are dictionaries. Now we know how we can access some list item. So this is zero location list item. This is first location list item. This is second location list item. We need to display this list item.

So we need to use second location. We know what we need to do here in the scale brackets specify two. This is all we need to do. So now we have third list item for each host. Now we need to access this end. We know this is key value pair and we know how to access this value. We’ll use this key. I will make one more change. In the exam you must be able to form the expression without doing all this. With practice you will know how to do this. So here we have this end location. So now we have expression. Now I will open this file again. So we need to use this expression. We’ll add plus one to this value. Because starting location of extended partition cannot be same as the end location of last partition which already exists on the desk. I will just clear everything. Here we’ll define task for creating extended partition. Creating extended partition parted then using device we know device partition number will be four. We need to enclose this in double quotation marks.

Part type would be extended part underscore start. So this is important. So here we can provide absolute value as well, because we already displayed endpoint or partition number third. We can just add plus one mebby to that value and set here the absolute value as start point. But instead I would use variable here st info partitions the second item on the list then dot and then we need to add plus one. We know why we are adding this and here important is you must specify unit because we are not using unit directive in this section and enclose complete expression inside double quotation marks. So here mindset unit is inside quotation marks. Now next part underscore end. We don’t need to define this here because we need to create extended partition using all the space which is end of the desk. State must be set to present. So here, default is info.

So don’t forget to set state to present. Now, next task is to create logical partition of size 200 MAB. Here I will provide description. Creating logical partition again we need to use parted module device. Partition number would be five part type here will be logical part underscore start we’ll use same expression. But here we need to change one thing. We know extended partition does not take space, it only takes some space for the metadata. Extended partition is meant to contain more logical partitions. So idly we should be able to use same starting location, but this is not the case. We must use plus two here just to leave some space for the metadata. Here we need to define partition end. I will just copy paste it and here I will write 20 two. So it means if you see the difference between partition start and partition end, it’s 200 MAB. State must be present.

So this is all we need to do for this task. I will save and exit again before execution. I will perform syntax check so everything seems okay. Before executing this command I will display all the Bloke devices which are already existing on all the remote nodes. For this I’m using command module. I will use command lsblk. I will execute this again. Here I did not use Become because we can display this as normal user or as regular user as well. So here we can see we have three partitions already created on all the remote nodes. These partitions were created during installation process. Now we’ll execute playbook ansible playbook partner YML. So it will take some time because facts need to be gathered here extended partition has been created. Logical partition has been created, so we have no errors. I will clear the screen again, I will execute this command. Here you can see two additional partitions for each remote node SDA four which is extended partition taking one k only because this is only for metadata. So this is our logical partition of size 200 mabuytes. So now you know how you can create extended partition and the logical partitions so important here is how to define part underscore start or I will say starting location of partition. You can give percentage value, you can give absolute value, you can use variable. All will work perfectly fine. This is up to you how you want to handles.

13. Task-Creating and Mounting filesystem using Playbook

Hello, welcome to this lecture. In this lecture we’ll learn how to create file system on partition or on some block device and how to mount file system. Here is task description create a playbook mount dot YML to format the device SDfive. So this is the logical partition we created in previous task with ext four file system mount the file system on this mount point mount should be persistent. We need to mount the file system persistently through fstab file.

Here are the contents of playbook we will be using for this task. Here target is all become must be set to true or yes we can set gather underscore facts to false because we don’t need to gather facts for this task. Then in the tasks section will define two tasks one task to create file system, other task to mount file system which will be created in task one.

In the first task we need to use file system module then using dev will specify block device. We want to create file system own in our case this is SDF five. Then using FS type directive we specify file system type which is ext. four as per task requirement. Then in the next task we’ll use mount module to mount this file system where I will say to mount the file system which will be created as a result of this task. Hereby using SRC or source we’ll specify file system to be mounted using path directive will specify mount point in case mount point does not exist, same will be created automatically. Here we must specify FS type. Then state is set to mounted, so state here can be mounted present or absent.

In case state is set to present entry in fstaf file will be created but file system will not be mounted. But when state is set to mounted, entry in fstav file will be created and file system will be mounted as well. So we need to use state set to mounted when state is set to absent. So file system will be unmounted and entry from fstav file will be deleted as well. 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. First of all, I will display documentation for file system module. This module creates a file system. So here we’ll use dev target path to device or image file. In our case this is bloke device then FS type which is mandatory dab is also mandatory file system type to be created.

Here is list of choices, we can use any of them in our task we need to use ext. four. We need to use only these two directives. Here you can find some examples, just go through them. I will quit, I will clear the screen. Now I will display documentation four mount module this module controls active and configured mount points in FS tab file again we’ll discuss only important directives.

We need to know FS tab file to use instead of FS tab but here we are using FS tab only. We don’t need this FS type file system type required when state is present or mounted in our case we are going to use state set to mounted so we must use FS type path which is mandatory path to the mount point. So using path we’ll specify mount point SRC device to be mounted on path. So here we’ll provide file system which is forward slash tab forward slash SGFI in our case required when state is set to present or mounted. We know we need to use state set to mounted then state which is mandatory. I already explained about this. You can just go through this.

If mounted, device will be actively mounted and appropriately configured in FS tab if the mount point is node present, same will be created. We are using this if unmounted, device will be unmounted without changing FS tab but entry in FS tab will remain unaffected. Present only specify that device is configured in FS tab but does not trigger or require a mount so it will create entry in FS tab file but device will not be mounted absent specify that device mounts entry will be removed from FS tab and will also unmount the device remove the mount point.

So here are the choices we can use. I will create now we’ll create playbook with name mount dot by ML three dashes on the top target is all become must be set to yes gather facts. I will set these two folds because we don’t need them. If we don’t specify this directive here by default facts will be always gathered unless we configure ansible config file note together facts then tasks section first task to create file system we know we’ll use file system module we’ll use dev to specify bloke device SST type ext. four this is all we need to do.

Then second task to mount file system module name file system to be mounted path to specify mount point directory which in our case is mntpartition. We know directory partition does not exist. Same will be created automatically. Don’t forget to specify FS type. This is mandatory because we are going to use state as mounted. This is all we need to do before execution. I will just do syntax check. Oh seems okay now we’ll execute playbook ansible playbook mount dot ML creating file system mounting file system you might have noticed this is green this is because I already executed this task to create file system during my testing, so no changes are done.

Now this is over. Now we’ll verify FSTF file using command module. We’ll also verify if the file system is mounted. NCB old here will specify command to display FSTF file we must use become so here we can see entry for our bloke device. So entry exists on each managed node now next I will execute list block devices. So here we can see our file system is mounted on this mount point. So this is ours.

Comments
* The most recent comment are at the top

Interesting posts

Preparing for Juniper Networks JNCIA-Junos Exam: Key Topics and Mock Exam Resources

So, you’ve decided to take the plunge and go for the Juniper Networks JNCIA-Junos certification, huh? Great choice! This certification serves as a robust foundation for anyone aiming to build a career in networking. However, preparing for the exam can be a daunting task. The good news is that this guide covers the key topics… Read More »

Mastering Microsoft Azure Fundamentals AZ-900: Essential Study Materials

Ever wondered how businesses run these days without giant server rooms? That’s the magic of cloud computing, and Microsoft Azure is a leading cloud platform. Thinking about a career in this exciting field? If so, mastering the Microsoft Certified: Azure Fundamentals certification through passing the AZ-900 exam is the perfect starting point for you. This… Read More »

The Impact of Remote Work on IT Certification Exam Processes

With remote work becoming the new norm, it’s not just our daily routines that have changed but also how we tackle IT certification exams. Gone are the days of trekking to testing centers; now, your living room can double as an exam room. This shift has brought about some fascinating changes and challenges. Let’s dive… Read More »

IT Risk Management: CRISC Certification Exam Essentials

Do you ever feel like the IT world is moving at warp speed? New tech seems to pop up every day, leaving you wondering how to keep up and truly stand out in your field. Companies are increasingly concerned about online threats, data leaks, and meeting legal requirements. That’s where the CRISC (Certified in Risk… Read More »

The Ultimate Guide to Mastering Marketing Automation for Email Wizards

Hey there, email aficionados! Welcome to your new favorite read – the one that’s going to turbocharge your email marketing game. You’re about to dive into the captivating world of marketing automation, a place where efficiency meets effectiveness, letting you boost your campaigns without breaking a sweat. Get ready to discover how automation can not… Read More »

Master YouTube Marketing with These 10 Powerful Steps

Welcome to the dynamic world of YouTube marketing! Whether you’re a seasoned pro or just getting started, harnessing the power of YouTube can significantly boost your brand’s visibility and engagement. With over 2 billion monthly active users, YouTube offers a vast audience for your content. But how do you stand out in such a crowded… Read More »

sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |