EX294 Red Hat Certified Engineer RHCE – Using Scripts for System Administration Tasks

  • By
  • January 19, 2023
0 Comment

1. Introduction

Hello. Welcome to section One. Using scripts for system administration tasks till now, we already learnt how to write ansible playbooks and how to use ansible ad hoc commands. In this section, we learn how we can use ansible ad hoc commands to run as shell script.

In fact, we will be doing nothing extra than we have learned so far. We’ll just put ansible ad hoc commands inside a file to run them as shell script. This is something important for you to know. Let’s move ahead with the first task of this section.

2. Task: Creating File and Symbolic Link Using Shell Script

Hello, welcome to this lecture. In this lecture we will learn how we can create file and symbolic link for the file using ansible ad hoc commands inside shell script. Here is task description. Create a script file dot sh to run ansible ad hoc commands for the following task tasks create one file results own pro nodes on this specific path so here we need to keep in mind we must create this specific path before we create this file. This is prerequisite configure full permissions at group level and read executions for others set markers user and group owner. We know how we can do this we’ll use honor and group directives with file module create symbolic link in root directory with default name so we’ll create symbolic link for this file in root directory default name means symbolic link will be named as results. Here are contents of our shell script we’ll create file with name file dot sh we’ll put three ansible ad hoc commands inside this file we will be using file module for all these commands.

With first command we’ll create this directory path which is prerequisite here we must use state set to directory and also we need to use become flag because we are going to create this directory path under root directory and we need root privileges with second command. We’ll create file with name results on this directory path and we’ll set permissions for group and others as per task requirements. We also need to set file owner as Mark and also group owner as Mark. Here state must be touch because we need to create zero length file on this directory path again we need to use Become. Then using this command we will be creating symbolic link for this file result file on this specific path and this is a destination this is a link name. We need to create symbolic link under rhode directory with the same name as that of file name which is default name.

So by default symbolic link is created with the same name as that of file. Even if we don’t specify this file name here state must be set to link to create symbolic link then become flagged to use root privileges we’ll save and quit. Then we need to execute this script as an symbol user. So first of all we must provide execution permissions on this script so here using this command we can provide execution permissions to all we can also restrict execution permissions only to user by using u plus x. Then we need to execute this script using this syntax dot forward slash then skip name. We know why we use this. If we don’t use dot forward slash the system will not able to find this script so you must use dot to run the script. Now let’s move to the ensable control node and start doing this task. Now we are on an ensable control node and I am logged in as ensable user here under tasks directory we need to create file with name file dot she here we need to put our ansible ad hoc commands I will change to insert mode ensable target is prod mode as per task description m to specify module A. To provide arguments we need to create directory path state must be set to directory become so this is all for first command. Next anceible probe again we need to use file material using dasha will provide arguments here we need to provide path of the file to be created.

Then using mode will configure permissions we know how to do this. For the group we need to provide full permissions and for others we need to provide read and execution permissions we need to set owner as mark user is already created on all remote nodes so we don’t need to worry about this. To set the group owner we’ll use group darktave then finally we’ll set straight to touch become third command ansible prode again we’ll use file module here we need to use SRC directive to specify source file for which we want to create symbolic link. So this is the source file dust. We need to create symbolic link under root directory with default name, which is results. Then important here is we must set state to link. We’ve already gone through documentation of file module. And we know all this become this is all we need to do I will save and quit now next step is to provide execution permissions to the script this is something you must keep in mind. Because by default file you create with extension dot she never has execution permissions. So here we can see this we’ll use chmode.

I will provide execution permissions to everyone you can provide permissions according to task requirements. The next step is to execute this script. So it will take few seconds this is completed and here we can see for these two tasks state is set to link. So these are tasks to create symbolic link. So here we have tasks to create results file and to set user owner group owner and to configure permissions so these first two tasks are to create directory path. So this is clear from the outcome of ansible control node. Now to verify we know we can use ansible ad hoc commands I will clear the screen. We’ll execute ansible then protein which is target.

We will be using default module which is command module using a option we’ll specify command to be executed. I will list attribute of this file using LS l here we must use Become here we have output we can see file has been created on the pro nodes and user and group owners are set to mark also at group level full permissions are configured and four others read and execution permissions are configured. Now again I will execute same command but this time I will list contents of root directory here we have output here we can see symbolic link has been created for this file with the name results under root directory for both pro nodes m host one and Most two. This is over. About this task.

3. Task: Creating User and Assigning supplementary Group Using Shell Script

Hello, welcome to this lecture. In this lecture we learn how we can create user and how we can assign supplementary group to user. Here is task description create a script user sh to run and see the ad hoc commands for the following tasks create user with username name RHCE own all manage nodes and set password as RHCE underscore pass use encryption sha five one, two we know how to use it.

Create group with name ex 294 and assign the supplementary group to this user. Use user IDs 2021 here we have contents of our script. We’ll create file with name user dot sh as per task requirement using first ansible ad hoc command will create group with name ex two nine four using group module this is prerequisite because we need to create group first only then we can assign this group to some user. Then using second and simple ad hoc command will create user. Here we need to use user module username is RHCE using password directly will set password. Here we know we need to use Ginger to filter password underscore hash to encrypt the password.

And this is the algorithm we need to use. Here you must keep in mind you must enclose this password RSE underscore path in single quotation marks. So in case you are using variable, you don’t need to enclose the variable. But here we are using value of the password. So here we must enclose this. Then using groups directive will assign this supplementary group to this user. So here you must keep in mind you must use groups in case you will use group it will not fail because group is also valid directive and is used to assign primary group. So this is something you must keep in mind. Then using UID will specify user ID become we’ll save this file and create the next.

We need to assign execution permissions on this script. Then we’ll execute this script. Let’s move to the ensuite control node and start doing this task. Now we are on ensable control node and I am logged in as ansible user. Here under Tasks directory will create file with name user dot sh as per task requirement I will change to insert mode. And here we’ll specify ensible ad hoc commands. Ansible all we need to execute these commands on all manage nodes. M to specify module we need to use group module to create group using dash A will specify arguments name of group to be created. Then I will set state to present. Although this is deferred behavior, I would always prefer to specify it. Become the second addo command to create user ansible all m we need to use user module a to specify arguments username is RHCE using password directly will set password. Here we need to use ginger two expression password we need to set RHCE underscore pass.

This must be enclosed in single quotation marks. Then using PY filter will specify Ginger to filter password underscore hash to encrypt the password, we know how to use it. Then we’ll use groups directive to assign supplementary group. So here you must keep in mind you are using groups, because group is also valid directive. Then using UID, we’ll specify user ID to be used. And finally I will set state to present. We must use dash dash become with these commands. Because we need root per villages to execute them. This is all we need to do. For this, I will save and create now. Next we need to assign execution permissions on this script. Execution permissions are provided to everyone. Now I will execute the script. It can take some time. It’s completed. Here we can see user with user ID two, zero, twenty one and username RSE has been created.

Supplementary group ex 294 has been assigned to this user. On the top, you will find first four task to create group. So we can see group ex 294 was created successfully. This is all for this task. Now, to verify, we’ll execute ensable ad hoc commands ansible all. I will display password file and I will grab for user RSCE. Here we can see entry for RSCE user in past WD file on each managed node. To be more clear, I will remove this filter. So now it’s more clear. So this is entry on m host three. This is entry on m host two. In similar way, you can verify for m host four and am host one.

Now I will clear the screen again. I will execute this command. But this time I will display shadow file. Here we must use Become, because to display this file, we need root privileges. Here we have output. Here we can see entry for RSE user. This is password in encrypted format. This is output tone Mhost one. In similar way, we can change for m host three, m host two and m host four. This is all about.

Comments
* The most recent comment are at the top

Interesting posts

The Growing Demand for IT Certifications in the Fintech Industry

The fintech industry is experiencing an unprecedented boom, driven by the relentless pace of technological innovation and the increasing integration of financial services with digital platforms. As the lines between finance and technology blur, the need for highly skilled professionals who can navigate both worlds is greater than ever. One of the most effective ways… Read More »

CompTIA Security+ vs. CEH: Entry-Level Cybersecurity Certifications Compared

In today’s digital world, cybersecurity is no longer just a technical concern; it’s a critical business priority. With cyber threats evolving rapidly, organizations of all sizes are seeking skilled professionals to protect their digital assets. For those looking to break into the cybersecurity field, earning a certification is a great way to validate your skills… Read More »

The Evolving Role of ITIL: What’s New in ITIL 4 Managing Professional Transition Exam?

If you’ve been in the IT service management (ITSM) world for a while, you’ve probably heard of ITIL – the framework that’s been guiding IT professionals in delivering high-quality services for decades. The Information Technology Infrastructure Library (ITIL) has evolved significantly over the years, and its latest iteration, ITIL 4, marks a substantial shift in… Read More »

SASE and Zero Trust: How New Security Architectures are Shaping Cisco’s CyberOps Certification

As cybersecurity threats become increasingly sophisticated and pervasive, traditional security models are proving inadequate for today’s complex digital environments. To address these challenges, modern security frameworks such as SASE (Secure Access Service Edge) and Zero Trust are revolutionizing how organizations protect their networks and data. Recognizing the shift towards these advanced security architectures, Cisco has… Read More »

CompTIA’s CASP+ (CAS-004) Gets Tougher: What’s New in Advanced Security Practitioner Certification?

The cybersecurity landscape is constantly evolving, and with it, the certifications that validate the expertise of security professionals must adapt to address new challenges and technologies. CompTIA’s CASP+ (CompTIA Advanced Security Practitioner) certification has long been a hallmark of advanced knowledge in cybersecurity, distinguishing those who are capable of designing, implementing, and managing enterprise-level security… Read More »

Azure DevOps Engineer Expert Certification: What’s Changed in the New AZ-400 Exam Blueprint?

The cloud landscape is evolving at a breakneck pace, and with it, the certifications that validate an IT professional’s skills. One such certification is the Microsoft Certified: DevOps Engineer Expert, which is validated through the AZ-400 exam. This exam has undergone significant changes to reflect the latest trends, tools, and methodologies in the DevOps world.… Read More »

img