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

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