Lab Guide: Deploying Cockpit with Ansible Lightspeed
A guide to using Ansible Lightspeed to generate a playbook that deploys and configures the Cockpit web console on Red Hat Enterprise Linux.
Introduction and Setup
|
Important Note About This Lab IBM watsonx Code Assistant models are continuously updated and improved. As a result, some specific task generation challenges in this lab may not work exactly as described due to model updates. This is expected behavior. The primary goal of this lab is to help you understand the key features of Ansible Lightspeed, including:
If a specific prompt doesn’t generate suggestions as expected:
|
In this challenge, you will use Ansible Lightspeed to generate an Ansible Playbook that automates the deployment and configuration of Cockpit, the RHEL web console.
Your Mission
Your goal is to use Ansible Lightspeed to generate a playbook that automates the following tasks:
-
Installs
cockpitusing theredhat.rhel_system_rolescollection. -
Copies a custom
cockpit.confconfiguration file to the target host. -
Starts and enables the
cockpitservice. -
Verifies that the service is available.
The examples used in this lab are available in the Ansible Lightspeed Demo repository.
|
Need Help? If you encounter difficulties or want to verify your work, you can reference the solution playbook at |
Task 1: Generate Playbook Tasks with Ansible Lightspeed
You will now edit a pre-created playbook file and use natural language prompts to have Ansible Lightspeed generate the necessary tasks.
-
Open the playbook file in VS Code.
-
Click on the VS Code tab at the top of your lab environment.
Work in a new browser tab: For the best experience with Ansible Lightspeed features, click the VS Code tab to open it in a new browser tab rather than using the inline embedded window.
-
On the left side of VS Code, locate the Explorer icon (it looks like two overlapping documents) and click it to show the file explorer.
-
In the file explorer, expand the folders: playbooks → infra → install_cockpit
-
Click on demo_install_cockpit.yml to open it in the editor.
-
-
Generate the
cockpitinstallation task.-
In the playbook file, find the line that says:
#- name: Install cockpit using redhat.rhel_system_roles collection -
Remove the
#symbol at the beginning of the line. You can either:-
Delete the
#manually, OR -
Click anywhere on the line and press
CTRL+/(Windows/Linux) orCMD+/(Mac) to uncomment it
-
-
Place your cursor at the very end of the line (after "collection")
-
Press
ENTERto create a new line -
Wait a moment - Ansible Lightspeed will show a suggestion in gray text
-
Press
TABto accept the suggestion_Lightspeed Highlight:_ The suggestion correctly uses the `redhat.rhel_system_roles.cockpit` role as specified in the prompt, incorporating best practices like using the Fully Qualified Collection Name (FQCN).
-
-
Generate the file copy task.
-
Find the next commented line:
#- name: Copy cockpit.conf.j2 to /etc/cockpit directory -
Uncomment the line by removing the
#(or pressCTRL+//CMD+/) -
Place your cursor at the end of the line (after "directory")
-
Press
ENTERto create a new line -
Press
TABwhen Lightspeed shows a suggestion_Lightspeed Highlight:_ Based on the `.j2` file extension in the prompt, Lightspeed correctly infers that the `ansible.builtin.template` module should be used and sets the correct file permissions.
-
-
Generate the multi-task to manage the service.
Multi-task prompts work differently: They start with a single
#, separate multiple tasks with an ampersand (&), and should NOT be uncommented. Just press ENTER at the end of the comment line.-
Find the line:
# Restart and enable service & wait 15 seconds for it to be available -
Do NOT uncomment this line - leave the
#symbol in place -
Place your cursor at the end of the line (after "available")
-
Press
ENTERto create a new line -
Press
TABwhen Lightspeed shows suggestions for BOTH tasks_Lightspeed Highlight:_ Lightspeed uses the full playbook context to infer that the service to restart is `cockpit`. It then uses the `&` separator to identify the second task and correctly uses the default Cockpit port (9090) in the `wait_for` module.
-
-
Save the playbook.
Click **File** → **Save** from the top menu, or press `CTRL+S` (Windows/Linux) or `CMD+S` (Mac).
Task 2: Review Ansible Lightspeed Training Matches
One of Ansible Lightspeed’s key differentiators is providing information on the potential training data used to generate suggestions.
-
Open the Lightspeed Training Matches view.
-
At the top of VS Code, click View in the menu bar
-
Select Open View…
-
In the search box that appears, type
Lightspeed -
Click on Lightspeed Training Matches from the list
-
-
Examine a training match.
-
In your playbook, click on any task name you generated
-
Delete one line of the generated code and press
ENTERto regenerate the suggestion -
Look at the Lightspeed Training Matches pane (usually at the bottom of VS Code)
-
You’ll see potential training sources. Click on any entry to see details including the content source, author, and license information.
-
Task 3: Run the Playbook
You can now choose to run the completed demo_install_cockpit.yml playbook using either the automation controller or ansible-navigator.
Option 1: Using Automation Controller
-
Commit and push the playbook to Git.
-
On the left side of VS Code, click the Source Control icon (it looks like a branch with circles)
-
You should see
demo_install_cockpit.ymllisted under "Changes" -
Hover over the file name and click the + (plus) icon that appears to stage the changes
-
At the top, in the "Message" box, type a commit message like:
Install Cockpit -
Click the Commit button (checkmark icon)
-
Click the Sync Changes button to push your playbook to the Git repository
-
-
Run the playbook from Automation Controller.
-
Click the Ansible Automation Platform tab at the top of the lab window
-
If you see a login screen, enter:
-
Username:
admin -
Password:
ansible123!
-
-
On the left sidebar, click Resources → Templates
-
Find the template named Deploy monitoring
-
Click the launch icon (🚀 rocket ship) on the right side of that row
-
Wait for the job to complete successfully (you’ll see a green "Successful" status)
-
Option 2: Using ansible-navigator
-
Open a terminal in VS Code.
-
Make sure you’re on the VS Code tab
-
Look at the top menu bar and click Terminal → New Terminal
-
A terminal panel will open at the bottom of VS Code
-
-
Navigate to the playbook folder.
In the terminal, type the following command and press `ENTER`:
cd playbooks/infra/install_cockpit -
Run the playbook with ansible-navigator.
Type the following command and press `ENTER`:
ansible-navigator run demo_install_cockpit.ymlThe playbook will run and show you the results. Press the `ESC` key to return to the terminal prompt when it's done.
Task 4: Verify the Cockpit Installation
Finally, verify that the Cockpit web interface is accessible.
-
Open the Cockpit web interface.
At the very top of your lab environment, click the **Cockpit** tab.
-
Verify Cockpit is running.
If the playbook completed successfully, you should see the Cockpit web console interface. This confirms that Cockpit was installed, configured, and started correctly!
Conclusion and Additional Resources
Congratulations! You’ve successfully created an Ansible Playbook using Ansible Lightspeed to deploy Cockpit!
|
Solution Playbook Available: If you encountered issues or want to compare your work, you can review the complete solution at |
Additional Resources
-
More information on Red Hat Ansible Lightspeed with IBM watsonx Code Assistant