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

  • By
  • January 20, 2023
0 Comment

10. Task: Creating Groups and Directory using Playbook

Hello. Welcome to this lecture. In this lecture we’ll learn how we can create supplementary groups and how we can create directory or directory path using Anvil playbook. Here is task description. Create a playbook with name group YML to perform below tasks.

Create directory path forward slash on web servers nodes create group testing on web service nodes and group networks on pro nodes. Here are the contents of playbook we will be using for this task. In this playbook we have two plays in the first play target is web servers web servers group become is set to yes because we can perform this section with root privileges then in the Tasks section I will define or will define two tasks. First task to create directory path second task to create group.

To create directory path, we’ll use or we need to use file module. Here we’ll specify path to be created, which is web HTML. Here we must set state to directory. If you remember, in case you need to create zero length file we set state to touch. But here we need to create directory path.

We’ll set state to directory. So in this case this is note mandatory web directory should exist it will create complete path then here using group module we’ll create group with name testing group name testing state present to create the group to delete the group, we’ll use state set to absent. In second place, target is pronounce or proud group. Again we need to set become to true. In the task section, we’ll define task to create group. We’ll use group module. Group name.

Must be networks state present to create the group this is all we need to do for this task now let’s move to ensure control node and start doing this task now we are on ensable control node and I am logged in as ansible user. We are inside tasks, directory. Here we need to create playbook. But before creating playbook I will open or I will display documentation for file module. Here I will go directly to state directive. So here state can be absent directory file hard link and touch.

We already used touch to create zero length file. So if state is directory, all intermediate sub directories will be created. So it means complete path will be created. I will clear the screen now I will display documentation for group module to manage presence of groups here we’ll use name name of group to manage and state absent present default is present even if we don’t specify, this group will be created but in case you need to delete the group, you must specify state as absent.

So this is all about this here? We need to create our playbook. Playbook name must be group dot YML three dashes. Dash. Then host. For the first play target is web servers. Nodes become must be set to true gather underscore facts I will set this to false. Then here in the tasks section we’ll define our task creating directory we know we need. To use file module here we need to specify the path directory path we want to create which is forward slash web, forward slash HTML state must be directory so this complete path will be created. Next ask is we need to create group creating group here we need to use group module name we need to create group with name testing state present which is default however I will mention it then here we’ll define the other play here target is probe nodes again become must be set to true. I will set gather facts to false. Then here in the task section I will define our task. Here we need to define only one task. To create group.

Creating group we need to use group module name networks state present I will not use this for this task anyway, this will be created because this is default. Now we’ll save this and exit. Before executing this playbook, we’ll just verify syntax. Everything seems okay. Now we’ll execute this playbook creating directory it has been created on web server web servers nodes creating groups then on the prode creating group, only one task. So on the web servers nodes two tasks are executed creating directory and creating group on the probe we defined only one task to execute.

So this task has been executed. So everything is okay. In the play recap you can see there is no error. So now we need to verify if the directory path has been created and group have been created. For this we’ll use ansible command line ansible web servers and here I will provide command to be executed first I will display group file which is present under etc directory. Here we can see our group testing is present on web servers nodes.

I will clear the screen will execute same command with prode as target here we see group with name networks has been created on probed nodes you can move and you can check for both nodes m host two and m host one similarly for the web server nodes you could check for both nodes. Now I will clear the screen again I will execute command on web servers nodes but this time LS LD four forward slash web HTML to verify if directory path has been created so here we see directory has been created. So this is all about.

11. Task: Setting SELinux context using Playbook

Hello, welcome to this lecture. In this lecture we’ll learn how we can set se Linux context type on directory and all the sub directories and files under this if there are any. We’ll do this section using ansible playbook. Here is task description create a playbook context dot YML to set SC Linux context type httpd underscore sys underscore content underscore t on this directory forward slash web HTML we know we created this directory path in previous lecture on all web servers, nodes settings should be persistent and context should be restored. We know when we set Se Linux context type persistently we must restore the context to make this effective. Verify the context type using ansible ad hook command here are the contents of playbook we will be using for this task. Here target is web servers group become must be set to true or yes because this is system administration task I will set gather underscore facts to false because we don’t need facts for this task.

Then in the tasks section we will be using SCF context module for this task. We’ll check the documentation of this module before doing this task. Here using target directory will specify directory. We need to set the context type own. So here is directory part with this specific syntax we know the syntax from Rscsa studies. Enclose this inside single quotation marks. Then using SC type directive we specify context type to be set. State should be present which is default. I’ll show you in the documentation then we know after setting context type persistently we must restore the context using restore cone command line we’ll use command module for this task. Using command module will execute restore cone with Irv options r four recursive to apply context type anything under this directory and own this directory v four verbose to display the changes which are done I here is for ignore the file which does not exist.

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 I’m already inside tasks directory. Before we move further I will display documentation for SCF context module. We know we need to use ansible dash talk command line. Here we have description for this module manages Se Linux file context mapping definitions so here we’ll discuss directives we will be using for this task se type which is mandatory. To specify Se Linux context type we need to set on the directory state whether the Se Linux file context must be absent or present. We need to set the context type we’ll use state set to present which is default.

We can omit this directive by default context will be set but in case we need to delete the context type we must use state set to absent then target which is mandatory target path on which we need to set the context type. Here we have one example here using target we are specifying directory path with this specific syntax. Don’t forget this. Then using Se type will provide Se Linux context type to be set. State will set this to present and after doing this, we need to reload context type for this. We will be using Command module now.

I will quit. This will clear the screen before setting context type. On the directory, I will display present context type set. On this directory. For this we’ll use ansible ad hoc command ansible web servers which is a target group. Here we’ll use command module. We don’t need to specify module because command module is default module. By using dash e option I will provide the command to be executed. LS dash LD capital z then here we need to provide directory path. This is all we need to do. Here we have context type default underscore stone this directory also I would like to mention I did not use Become here.

Because as a normal user we can display this now we’ll create our playbook with name context YML here we know three dashes on the top target is web servers become must be set to true will set gather underscore facts to false. Here in the tasks section we’ll define our task first task setting context type I will provide some description. Here we know we need to use SCF context module and here, using target directive, will specify directory. Path on which we need to set context type, which is web HTML. Then this specific syntax enclose the expression inside single quotation marks. Then, using SD type directive, will specify context type to be set httpd underscore sys underscore content underscore T state will set this to present this is all we need to do for first task here we’ll define our second task restoring context type here we need to use command module here we’ll type command to be executed.

We know we need to use Irv options here, then directory path forward slash web HTML. So here we are not using this specific syntax. We just need to provide directory path. This is all we need to do before executing this playbook I will perform syntax check everything is fine here I would like to mention one important thing because we installed our managed nodes with minimum install option so packages related to policy core utils are missing. I installed package Policy core utils with Asterisk. In the end, on all the managed hosts I did this section offline, so please install this package before doing any task related to AC Linux.

Now I will execute this playbook ansible playbook context YML setting context type. It will take some time. When you do any operation related to context, it always takes some time. It’s done on amhost four. It’s now being done on M host three. We need to wait for a few seconds more. So this is the first task in our play. It’s completed a second task completed very fast. So we have two changes done due to this playbook and we don’t have any error. So now what we’ll do by using ansible ad hoc command will verify we know we need to execute this. So we have context type set on this directory path if there would have been some sub directories or files under this so context type should have been set on those as well. This is all.

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/    |