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

  • By
  • January 20, 2023
0 Comment

4. Task: Creating file, Setting Owner and Configuring permissions using Playbook

Hello welcome to this lecture. In this lecture we’ll learn how we can create file own manage nodes using ansible playbook and how we can set user owner group owner on the file and how we can configure permissions on this file. Here is task description create a playbook named file dot YML to create file mark underscore file under root directory on all managed nodes user and group ownership must be set to mark configure full permissions for user read and write at group level and no permissions for others on this file set group ID bit.

Here are the contents of our playbook which we are going to use for this task so a target is all because we need to execute this playbook on all the managed nodes we must set become directive to true because we are going to create file under root directory for this we need root privileges. I will set gather underscore facts to false because we don’t need facts for this playbook in the tasks section will define our task we will be using or we need to use file module using path will provide path of file to be created here.

Keep in mind this directory must exist. We are using root directory here. We know this is already existing and it exists always. But in case you are using some other directory that should exist by using honor directory we are setting owner on this file by using group, we’ll set group owner then using mode will configure permissions on this file. This two is four to set group ID bit in case you need to set user ID. Bit. You must use four seven to configure permissions for the user.

We need to configure full permissions for user, which is four plus two plus one seven six to configure permissions at group level. We need to configure, read and write permissions at group level which is four plus two. No permissions for others. So here we are. Using zero state, must be touch. This will create empty file and set user and group ownership according to task description.

Also, it will configure permissions according to task description. 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 we are already inside tasks directory where we need to create our playbook. Before we create playbook, I will display documentation for file module. I know we’ve already gone through the documentation. We’ll just check this quickly. And here we need to use group name of the group that should own file or directory. In our case, we need to set group ownership to mark on this file. So default is null.

Not used. We will be using mode to configure permissions. We know what to do here then owner to set user. That should own the file. Default is null. Not use path to specify path being managed. In our case, this is forward slash root mark underscore file. Then important is state to create zero length file, we need to use touch. So here we are creating empty file. We’ll use touch. This is all we need to do. Again, we have some examples here. Now I will create playbook with name file dot YML. I will change to insert mode. Three dashes on the top space hosts all we must set become to true. I will set gather facts to false. Then here in the tasks section, we will define our task. Here I will provide description of task creating file, setting permissions and GID bit. We need to use file module path which is forward slash root mark underscore file owner mark group mark mode which should be enclosed in single quotation marks 2760 state touch.

This is all we need to do in the end, three dots I will save and quit. Now before I execute, I will just verify syntax. So this playbook test syntax check all seems okay. Now we’ll execute this playbook. This will create mark underscore file on all the managed nodes under root directory. So we have no error. We can check from the play recap change is equal to one where we can see file has been created on all the managed nodes. Now I will execute ansible Adobe command to verify our configurations. Ensible all A here I will provide command to be executed.

LS dash l forward slash root forward slash mark underscore file. This is all we need to do. I will execute this command. We have error. Permission denied. So normally as regular user, we should be able to display this. But why? This has not happened in this case because we removed all permissions for others. We must use become here to execute this as root user with root privileges. So here we can see user owner and group owner are set to mark full permissions at user level read write at group no permissions for others. This capital s means group ID bit is set. So this is all about this task.

5. Task: Creating file, Setting permissions, Copying content using Ad-hoc commands

So welcome to this lecture. In this lecture, we are going to perform task to create zero length file and to configure permissions on this file for others. We also need to copy one string to this file. We’ll do this section using ansible ad hoc commands. Here is task description. Using ansible commands, create file one dot TXT under root directory on oval manage nodes. File should contain text. This text file is created using an sybil. Remove all permissions for others on this file. Here are two commands we need to execute for this task. Ansible all we need to execute command on all remote nodes. We need to use file module and here using path will provide path of the file to be created. Using mode will configure permissions for other. We need to remove all permissions for others. Here we’ll use symbolic mode for others minus Rwx read, write and execution permissions.

So using the symbolic mode we’ll remove all the permissions for others. State is equal to touch to create zero length file. Become we need root permissions or root privileges. To create file under root directory. Don’t forget to enclose list of arguments inside double quotation marks. Then using next addo command we’ll copy this string to this file using copy module. Now let’s move to the ensable control node and start doing this task. Now we are on an ensible control node and I am logged in as ansible user. I’m inside tasks directory from where we need to execute our ad hoc commands. First, ansible command we need to execute to create file and configure permissions ansible all m file a to provide arguments using path directive will specify path.

This is the path of file to be created. Then we’ll set mode to o minus Rwx. To remove all permissions for others, state must be set to touch. This is all we need to do. Become to use pervillage escalation, I will execute this command. So file has been created. We have yellow output. We don’t see any error. So here you can see zero in the end. So it means no permissions for the others. Now I will clear the screen. Now we need to execute our next ado command. Ansible oil m copy a to provide arguments here we need to use content. This text file is created using an Syble. I will enclose the string inside single quotation marks. And then we need to provide dust which is forward slash root forward slash file one dot TXT. This is all we need to do. Enclose all the arguments in double quotation marks. Dash dash become it’s taking some time. So it’s completed.

So string has been copied to this file. Now we’ll verify using ansible ad hoc commands ansible all a here will execute LS is l four forward slash root file one dot TXT again mind here we must use Become because we removed all permissions for others. So here is output. So no permissions for the others. So everything seems okay. Now, we need to display contents inside this file. For this, we’ll use cat. So here we have contents inside this file. This text file is created using an siebel is all about this task.

6. Task: Archiving Directory using Playbook

Hello, welcome to this lecture. In this lecture we’ll learn how we can archive contents of a directory and how we can compress archive using some compression algorithm. Here is task description using ansible playbook archive dot YML archive contents of etc directory into tas under root directory. So we need to place archived file under root directory. Playbook should be executed on web servers nodes so we need to do this task only for web servers nodes which are m host three and four compress the archive using bZIP two we’ll use this compression method to compress the archive. Here are the contents of playbook we will be using for this task. In the target we’ll specify web servers.

Become is equal to yes because we are going to archive contents of etc directory we need root privileges for this I will set gather underscore facts to false. Then in the Tasks section we’ll define our task. Here we’ll use Archive module using path directive will provide path of the directory to be archived in our case etc. Then using dest directive will provide where archive file should be created and what should be the name of archive or archived file. In our case archived file should be placed under root directory.

We’ll provide path here etc tar BG two so this is for compression method we are going to use. You must use this extension. So here using format will tell ansible to use the compression method which is BJ two. This is all we need to do 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. We are inside tasks, directory. Here we need to create playbook. Before creating playbook I will display documentation for Archive module.

So here we can find description about this module paxan archive. So then we have number of directives for this task we will be using dest the file name of destination archive, which in our case is forward slash root forward slash etc dot task dot BJ two because we are compressing the archive as well. Format type of compression to use. So this is default but we’ll specify BJ two. We can also define group owner, we can also configure permissions but we don’t need to do for this task path using path remote absolute path remote means path on the managed node.

So in our case it’s forward slash etc. So this is all we need to do for this task. So here we have some examples, just go through them, I will clear the screen and here we need to create our playbook with name archive dot YML again we know three dashes on the top space hosts web servers so here you can mention this like this as well. Both will work perfectly fine. Become must be set to true gather facts I will set this to false. Then here in Tasks section we’ll define our task here we know we need to use archive module. We need to set path to forward slash etc destroy slash root because we need to place archived and compressed file under root artery etc BJ two format colon space BJ two this is all we need to do three dots in the end I will save and quit.

Now, before we execute playbook will verify syntax all seems okay now we’ll execute this playbook so task execution has been started so it’s completed. So we have contents of etc directory archived and compressed for web servers nodes now using ansible command line we’ll verify this ansible web servers a and here I will list contents of root directory this is all we need to do just to verify a file has been created on this path we must use Become. So here we can see our file etc tar BJ two same four m host three and four so 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/    |