LightSpeed

Skill Level: Intermediate

1. Overview

RHEL Lightspeed is a generative AI assistant designed to help new and experienced users when they interact with RHEL through the command line. It can help with several tasks such as: answering RHEL related questions, assisting with troubleshooting, assisting with deciphering log entries, and many others. The Command Line Assistant (CLA) powered by RHEL Lightspeed is what we will use for these exercises. The CLA provides a natural language interface and, through RHEL Lightspeed, can incorporate information from sources such as the Red Hat documentation, knowledge base articles, reference architectures and other resources. It is a very powerful tool that enables admins to more easily manage, troubleshoot, and work with RHEL systems.

For brevity, the two informational messages below will be omitted from the sample output even though they show up in the live exercise.

This feature uses AI technology. Do not include any personal information
or other sensitive information in your input. Interactions may be used
to improve Red Hat's products or services.

and

Always review AI-generated content prior to use.

2. Getting Started

For these exercises, you will be using the host node2 as user root.

From host bastion, ssh to node2.

ssh node2

Use sudo to elevate your privileges.

[[ "$UID" == 0 ]] || sudo -i

Verify that you are on the right host for these exercises.

workshop-lightspeed-checkhost.sh

You are now ready to proceed with these exercises.

3. Core Concepts

This exercise will expand on the basics of RHEL Lightspeed by introducing additional capabilities beyond just asking questions. These include:

  • piping command output to the command line assistant

  • attaching a file to the command line assistant

4. Start the Apache Web Server - Maybe?

Let’s begin by issuing the command to start the Apache web server

systemctl start httpd

The web service didn’t start properly, and instead gave us an error message and a couple of commands to run to get possible further information.

Job for httpd.service failed because the control process exited with error code.
See "systemctl status httpd.service" and "journalctl -xeu httpd.service" for details.

5. Have RHEL Lightspeed help figure out the issue

Running either or both of the commands will point to the error, but especially for those not very familiar with systemd and/or journalctl, the output can be a little confusing to read. Let’s see if the CLA can make it easier.

journalctl -xeu httpd.service | c "help find why httpd failed to start"
The logs indicate that the Apache HTTP Server (httpd) failed to start
due to a syntax error in the configuration file /etc/httpd/conf/httpd.conf.
Specifically, the error message states
"httpd: Syntax error on line 34 of
     /etc/httpd/conf/httpd.conf: ServerRoot must be a valid directory".

This error suggests that the ServerRoot directive in your Apache
configuration file is either missing or incorrectly set. The ServerRoot
directive specifies the location of the Apache HTTP Server's binary files.

To resolve this issue, follow these steps:

1. Open the Apache configuration file using a text editor with root privileges.
   For example, you can use nano:

   ``
   sudo nano /etc/httpd/conf/httpd.conf
   `

2. Locate the ServerRoot directive, which should be near line 34. It typically
   looks like this:

   `
   ServerRoot "/etc/httpd"
   `

3. Ensure that the path specified is correct and the directory exists. In this
   case, it should be /etc/httpd.

...<output truncated>...

Great! That’s probably the issue, but what if we don’t know how to use an editor, just a few basic Linux commands? Let’s see what the ServerRoot line looks like (note: the "^" character tells the grep command to start searching for "ServerRoot" at the beginning of each line in the file, so it won’t match comment lines that start with "#")

grep ^ServerRoot /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpdd"

This is telling us that the ServerRoot directory should be /etc/httpdd. That doesn’t look quite right, let’s check anything in the /etc directory starting with htt

ls -ld /etc/htt*
drwxr-xr-x. 5 root root 105 May  8 18:24 /etc/httpd

Sure enough, "httpdd" should be "httpd". Is there a way to change it in the file without knowing how to use the editor? Let’s ask RHEL Lightspeed. Since the previous answer included using an editor, this query will specify to use the command line

c "how to change /etc/httpdd to /etc/httpd in file /etc/httpd/conf/httpd.conf using command line"
To change the configuration directory from /etc/httpdd to /etc/httpd
in the httpd.conf file using the command line, you can use the sed
command. Here's how you can do it:

1. Open a terminal.
2. Use the sed command to replace /etc/httpdd with /etc/httpd in the
httpd.conf file. The command would look like this:

[bash] Snippet ────────────────
sed -i 's|/etc/httpdd|/etc/httpd|g' /etc/httpd/conf/httpd.conf
────────────────────────

This command uses sed to perform a global search and replace (-i for
in-place editing, s for substitute, and g for global).

3. After running this command, the httpd.conf file should now reference
/etc/httpd instead of /etc/httpdd.

...<output truncated>...

The "sed" command can be used to make the change to the file in place without having to use an editor.

sed -i 's|/etc/httpdd|/etc/httpd|g' /etc/httpd/conf/httpd.conf

Now let’s verify that the line is now correct.

grep ^ServerRoot /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd"

That looks good, so we should be able to start the Apache webserver now and verify the status.

systemctl start httpd
systemctl status httpd
● httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
     Active: active (running) since Thu 2025-05-08 21:25:49 UTC; 51s ago
 Invocation: 2a01a4ce7df24be3a6986896f2c17109
       Docs: man:httpd.service(8)
   Main PID: 83947 (httpd)
     Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0; Bytes served/sec:   0 B/sec"
      Tasks: 177 (limit: 45075)
     Memory: 13.8M (peak: 14.5M)
        CPU: 185ms
     CGroup: /system.slice/httpd.service
             ├─83947 /usr/sbin/httpd -DFOREGROUND
             ├─83948 /usr/sbin/httpd -DFOREGROUND

...<output truncated>...

6. Apache is up and running! Now let’s add web developer accounts

This can be done in a number of ways, but let’s take this opportunity to illustrate passing a file to the Command Line Assistant. First create a file with 3 account names

echo bob > webdevs.txt ; echo susan >> webdevs.txt ; echo francis >> webdevs.txt

Now ask RHEL Lightspeed to write a script that will create user accounts for the list of users in that file and make sure that they are in the apache group so they can do web development.

c -a webdevs.txt "using the attached file write a script that will create user accounts that are also in the apache group"
To create user accounts that are also members of the Apache group in
Red Hat Enterprise Linux, you can use the useradd command along with
the usermod command to add users to the group. Here's a script that
accomplishes this for the users 'susan', 'bob', and 'francis':

[bash] Snippet ────────────────
#!/bin/bash

# Define the users to be created
users=("susan" "bob" "francis")

# Define the Apache group name
apache_group="apache"

# Loop through the list of users
for user in "${users[@]}"; do
    # Create the user if it doesn't exist
    if ! getent passwd "$user" > /dev/null; then
        useradd -m "$user"
    fi

    # Add the user to the Apache group
    usermod -aG "$apache_group" "$user"
done

echo "Users $users[] have been created and added to the Apache group."
────────────────────────

Instructions to Use the Script
·······························

1. Save the script to a file, for example, create_users.sh.
2. Make the script executable by running:
   `bash
   chmod +x create_users.sh
   `
3. Execute the script with:
   `bash
   ./create_users.sh
   `

Notes
······

...<output truncated>...

7. Conclusion

That concludes this unit on the Command Line Assistant for RHEL Lightspeed. You can find more info in the official Red Hat Command Line Assistant documentation or the man page (use "man c" ).

Time to finish this unit and return the shell to its home position.

workshop-finish-exercise.sh