Chapter 4. Developing Ansible content As an automation developer, you can use Red Hat Ansible Lightspeed to implement your organization's automation strategy. Red Hat Ansible Lightspeed can help you create and use custom automation content. This chapter provides information about how to get set up as an automation developer on Red Hat Ansible Lightspeed, with details on how to: Access the Ansible Lightspeed portal as an automation developer Install and configure the {AnsibleVSCode} Create task recommendations Create playbooks and view playbook explanations Provide feedback on the Ansible Lightspeed service 4.1. Accessing the Ansible Lightspeed portal as an automation developer You can access Red Hat Ansible Lightspeed through the Ansible Lightspeed portal . After you enter your Red Hat Single Sign-On (RH-SSO) account credentials, your account is authenticated and you are granted access. Your assigned user role is displayed on the login screen of the Ansible Lightspeed portal. Table 4.1. User login scenarios Scenario Result You are a RH-SSO user. NOTE: This is the typical scenario for accessing Red Hat Ansible Lightspeed as an Ansible user. You are routed to the Red Hat Ansible Lightspeed paid commercial offering. You are a RH-SSO user, but your organization administrator has not configured Red Hat Ansible Lightspeed to connect with IBM watsonx Code Assistant. You are routed to the Red Hat Ansible Lightspeed paid commercial offering with a message that your organization administrator has not configured a model for your organization. 4.1.1. Logging in to the Ansible Lightspeed portal as an automation developer Procedure Go to the Ansible Lightspeed portal login page . Click Log in Log in with Red Hat . Enter your Red Hat account username and password. On successful authentication, the login screen is displayed along with your username and your assigned user role. 4.1.2. Logging out of the Ansible Lightspeed Service To log out of the Ansible Lightspeed Service, you must log out of both the Ansible Lightspeed VS Code extension and the Ansible Lightspeed portal. Procedure Log out of the Ansible Lightspeed VS Code extension: Click the Person icon . You will see a list of accounts that VS Code is logged into. Select Ansible Lightspeed Sign Out . Log out of the Ansible Lightspeed portal: Navigate to the Ansible Lightspeed portal login page . Click Log out . 4.2. Installing and configuring the Ansible VS Code extension Red Hat Ansible Lightspeed with IBM watsonx Code Assistant is integrated with the Ansible Visual Studio (VS) Code extension in VS Code. The Ansible VS Code extension, with Red Hat Ansible Lightspeed features enabled, automatically collects recommendations, usage telemetry, and Ansible YAML file state through automated events. To access Red Hat Ansible Lightspeed, all Ansible users must install and configure the Ansible VS Code extension in their VS Code. The Ansible VS Code extension uses the Ansible-specific IBM watsonx Granite model configured in the Red Hat Ansible Lightspeed administrator portal as the default mode for all users in your organization. You can also use a custom, fine-tuned model if your organization administrator has created a custom model and has shared the model ID with you separately. Use the model-override setting in the Ansible VS Code extension to override the default model, and use the custom model instead. Using a custom model enables you to improve the code recommendation experience and tune the model to your organizational automation patterns. For example, if you are using Red Hat Ansible Lightspeed both as an organization administrator and a user, you can test the custom model for select Ansible users before making it available for all users in your organization. For more information, see Configuring custom models . 4.2.1. Connectivity requirements To generate code recommendations, the Ansible Lightspeed service in Visual Studio (VS) Code editor requires access to the following outbound domain: https://c.ai.ansible.redhat.com The outbound connections are encrypted on TCP protocol port 443. 4.2.2. Installing the Ansible VS Code extension Prerequisites VS Code version 1.70.1 or later. Note You can also install VScode derivatives, such as VScode Insider or VS Codium. Procedure Open the VS Code application. From the navigation menu, click the Extensions icon. In the Search field, enter Ansible . Select Ansible to choose the Ansible language support extension published by Red Hat. Click Install . After installation is complete, verify your VSCode installation: Create a new YAML file using the .yml or .yaml file extension. From the Status toolbar, click the language indicator and select Ansible to associate the Ansible language type with the new YAML file. Start writing a test playbook. Contextual aids are displayed as you start creating your content. 4.2.3. Configuring the Ansible VS Code extension You can configure the Ansible VS Code extension to enable Red Hat Ansible Lightspeed and specify it's portal URL and IBM watsonx Code Assistant model ID. Prerequisites Your organization administrator has configured an IBM watsonx Code Assistant model for your organization. Procedure Open the VS Code application. From the Activity bar, click the Extensions icon . From the Installed Extensions list, select Ansible . From the Ansible extension page, click the Settings icon and select Extension Settings . Select Ansible Lightspeed settings, and specify the following information: Select the Enable Ansible Lightspeed checkbox. In the URL for Ansible Lightspeed field, verify that you have the following URL: https://c.ai.ansible.redhat.com/ . Select the Enable Ansible Lightspeed with watsonx Code Assistant inline suggestions checkbox. Optional: If you want to use the custom model instead of the default model, in the Model ID Override field, enter the custom model ID. The model-override setting enables you to override the default model and use the custom model, after your organization administrator has created a custom model and has shared the model ID with you separately. Your settings are automatically saved in VS Code. The following illustration displays the configured settings for the Ansible VS Code extension: Figure 4.1. Configured settings for the Ansible VS Code extension Note If your organization recently subscribed to the Red Hat Ansible Automation Platform, it might take a few hours for Red Hat Ansible Lightspeed to detect the new subscription. In VS Code, use the Refresh button in the Ansible extension from the Activity bar to check again. Additional resources Troubleshooting Ansible Visual Studio Code extension errors 4.2.4. Logging in to Ansible Lightspeed through the Ansible VS Code extension After installing and configuring the VS Code extension, you can log in to the Ansible Lightspeed service. 4.2.4.1. Sign-in options Red Hat Ansible Lightspeed provides different sign-in methods depending on whether you are using the cloud service or the on-premise deployment. Ansible Lightspeed on-premise deployments Users are authenticated using your Red Hat Ansible Automation Platform login. To sign in, you can use the Connect button in the Ansible Lightspeed view, or the Sign in with Ansible Lightspeed to use Ansible option in the Accounts menu. Once prompted in the browser, select Log in with Ansible Automation Platform , and log in with the authorization mechanism that your automation controller is configured with. Ansible Lightspeed cloud service Users are authenticated using Red Hat Single Sign-On (RH-SSO). To sign in from VS Code, you can use the Connect button in the Ansible Lightspeed view, or the Sign in with Ansible Lightspeed to use Ansible option in the Accounts menu. Follow the on-screen prompts to log in and access the Ansible Lightspeed service using your RH-SSO. Note If you are using a cloud development environment at a domain unknown by Ansible Lightspeed, such as on-premise Red Hat OpenShift Dev Spaces, your Accounts sign-in menu provides the option Sign-in with Red Hat to use Ansible . This option uses a device code flow to successfully complete the sign-in process and requires the Red Hat Authentication extension v0.2.0 or later. If you require this authentication flow but don't see the Sign-in with Red Hat to use Ansible option, ensure you are using the Ansible VS Code extension v24.5.2 or later. 4.2.4.2. Procedure Open the VS Code application. Sign in using either the Connect button in the Ansible Lightspeed view or the Accounts menu. Sign in using the Connect button : From the VS Code activity bar, click the Ansible icon. In the Ansible Lightspeed view, click Connect . Follow the on-screen prompts to sign in to Ansible Lightspeed. Sign in using the Accounts menu : From the VS Code activity bar, click the Accounts menu. Sign in with Ansible Lightspeed to use Ansible or sign in with Red Hat to use Ansible, depending on the sign-in option you are presented with. Note The sign-in options are displayed when the VS Code extension is in an active state. The extension is activated after you open the Ansible side panel or after you open an Ansible file in the VS Code editor. If you do not see this option, use the Connect button to link to the Ansible Lightspeed service. If you are using a cloud development environment at a domain unknown by Ansible Lightspeed, such as on-premise Red Hat OpenShift Dev Spaces, your Accounts sign-in menu provides the option Sign-in with Red Hat to use Ansible . This option uses a device code flow to successfully complete the sign-in process and requires the Red Hat Authentication extension v0.2.0 or later. If you require this authentication flow but don't see the Sign-in with Red Hat to use Ansible option, ensure you are using the Ansible VS Code extension v24.5.2 or later. Follow the on-screen prompts to sign in to Ansible Lightspeed. On successful authentication, the login screen is displayed along with your username and your assigned user role. 4.2.5. Logging out of the Ansible Lightspeed Service To log out of the Ansible Lightspeed Service, you must log out of both the Ansible Lightspeed VS Code extension and the Ansible Lightspeed portal. Procedure Log out of the Ansible Lightspeed VS Code extension: Click the Person icon . You will see a list of accounts that VS Code is logged into. Select Ansible Lightspeed Sign Out . Log out of the Ansible Lightspeed portal: Navigate to the Ansible Lightspeed portal login page . Click Log out . 4.3. Creating task recommendations Red Hat Ansible Lightspeed is integrated into Visual Studio (VS) Code through the Ansible VS Code extension. You can request code recommendations for your task intent by using Ansible VS Code extension. You can perform the following tasks from the Ansible VS Code extension: Create single task or multitask requests by using natural language prompts Create a single task prompt Write a description of your task in the - name: key of a new task line in your Ansible file. For example, to automate a task of installing PostgreSQL server, you can enter the prompt - name: Install postgresql-server . Create a multitask prompt Place your cursor on a new line in your Ansible YAML file at the correct indentation, and start your prompt with a Pound key (#). Write the descriptions of your tasks, separating each prompt by using Ampersand symbols (&). For example, to automate a multitask of installing PostgreSQL server and running the initial PostgreSQL setup command, you can enter the prompt # Install postgresql-server & run postgresql-setup command . The Ansible Lightspeed service reads the text, interacts with the IBM watsonx Code Assistant model, and generates Ansible task recommendations based on your natural language prompt. Note Currently, Red Hat Ansible Lightspeed supports user prompts in English language only. However, there could be instances where the training data that was used to train the IBM watsonx Code Assistant models included non-English language. In such scenarios, the model can generate code recommendations for prompts made in the same non-English language, but the generated code recommendations might or might not be accurate. View the content source matching results For each generated code recommendation, Red Hat Ansible Lightspeed lists content source matches, including details such as potential source, content author, and relevant licenses. You can use this data to gain insight into potential training data sources used to generate the code recommendations. Provide feedback on the Ansible Lightspeed service The Ansible Lightspeed service learns your organizational patterns and improves the code recommendation experience over time. You can provide feedback on whether the generated code recommendations were suitable for your task intent. This feedback enables Red Hat Ansible Lightspeed with IBM watsonx Code Assistant to improve on the quality of its suggestions. 4.3.1. Best practices to improve the recommended guidance Follow these guidelines to improve the likelihood of a quality code recommendation. Ensure that your YAML file is properly formatted. See the Ansible YAML syntax guidelines for details. Avoid context switching within a single playbook file. The Ansible Lightspeed service attempts to correlate earlier tasks to the active recommendation, and the entire contents of the file before the cursor position are used as context by the model. If the earlier task is not relevant to your prompt, VS code provides inline suggestions instead of code recommendations. Reword your natural language prompts to get code recommendations that match your task intent. If you get a recommendation that does not align with the intent of your task name, then rewording your prompt to provide more information about what is desired can lead to improved results. Use descriptive prompts and provide additional content to improve the code recommendations. Red Hat Ansible Lightspeed reads the full Ansible YAML file when generating a code recommendation. Using descriptive prompts and having additional YAML file content related to the desired task improves the code recommendation. For example, you can add the Ansible tasks and appropriate playbook and variable names to improve the code recommendations. 4.3.2. Creating single task recommendations You can request code recommendations for a single task by entering natural language prompts in Ansible VS Code extension. For example, to automate a task of installing a PostgreSQL server, you can enter the prompt - name: Install postgresql-server . The Ansible Lightspeed service reads the text, interacts with the IBM watsonx Code Assistant model, and generates the code recommendations. Prerequisites You meet one of the following requirements: Your organization has a trial or paid subscription to both the Red Hat Ansible Automation Platform and IBM watsonx Code Assistant. Your organization has a trial or paid subscription to the Red Hat Ansible Automation Platform, and you have a Red Hat Ansible Lightspeed trial account. You have installed and configured the Ansible VS Code extension . Procedure Log in to VS Code with your Red Hat account. Create a new YAML file or use an existing YAML file: Create a YAML file: Select File New Text File . From the lower right of the screen, click Plain Text , and in the language mode, select Ansible . Save the file as a YAML file format extension ( .yml or .yaml ). Use an existing YAML file: On the bottom right of the screen, click the existing language mode, and in the language mode settings, select Ansible . Note If you do not see the language mode section in your VS Code editor, from the Command Palette, select Configure Language Mode Ansible . Verify that you see an entry for Lightspeed on the status bar at the lower right of VS Code. If Ansible is already selected as the desired language but the Lightspeed entry is not displayed, re-select Ansible as the language mode. The following illustration shows Lightspeed and Ansible entries on the VS Code status bar. Figure 4.2. Ansible and Lightspeed set as selected language mode Optional: If you see an error message about missing Ansible lint, you can install the missing module or disable it. Perform any one of the following tasks: Install Ansible lint: For installation information, see the Installing section of the Ansible Lint documentation. Disable Ansible lint: From the Activity bar, click the Extensions icon . From the Installed extensions list, select Ansible . From the Ansible extension page, click the Settings icon and select Extension Settings . Clear the Ansible › Validation › Lint: Enabled checkbox. Create a playbook or use an existing playbook. For more information, see the Getting started with playbooks guide. In the playbook, provide the following information to request code recommendations for a single task: Add a new Ansible task by starting a new line with - name: at the correct indentation. Add a detailed natural language prompt in the task description after - name: on the same line. For example, you can specify the following single task prompt: - name: Install postgresql-server Press Enter directly after the task description. Keep the cursor at the same location in your file, and wait for the code recommendation results to populate. The Ansible Lightspeed service is engaged, and it starts generating code recommendations for a single task. Important Ansible Lightspeed service takes around 5 seconds per task to populate the code recommendations. If you are using a multitask prompt, the Ansible Lightspeed service takes a bit longer (number of tasks times 5 seconds) to populate the results. Do not move your cursor or press any key while the code recommendation is being generated. If you change the cursor location or press any key, Ansible VS Code extension cancels the request and the Ansible Lightspeed service does not process your request. When the Ansible Lightspeed service is engaged, a Lightspeed processing status indicator is displayed in the lower right of the screen to denote that your code recommendation is being generated. View your code recommendations and ensure that the recommendations match your task intent. The following illustration shows the code recommendations generated by the Ansible Lightspeed service for the single task Install postgresql-server : Accept or reject the code recommendations: To accept a code recommendation, press Tab . To reject a code recommendation, press Esc . Note If you reject a recommendation, you can modify the prompt and review the generated code recommendations once again to match your task intent. On the ANSIBLE: LIGHTSPEED TRAINING MATCHES tab, view the content source matching results. The following illustration shows the training matches found in existing Ansible Galaxy content for the task prompt Install postgresql-server : Click Save to save the code recommendation changes in your Ansible YAML file. Additional resources Troubleshooting Ansible Visual Studio Code extension errors Troubleshooting Ansible code bot errors 4.3.3. Creating multitask recommendations You can request multitask code recommendations by entering a sequence of natural language task prompts in Ansible VS Code extension. In a YAML file, start your prompt with a pound symbol (#), and separate each prompt by using the ampersand symbol (&). Example of a multitask prompt For better readability, you can split your multitask inline prompts over multiple lines. To achieve this, end your current line with an ampersand symbol (&) and start the line with the hash symbol (#). Example of a multitask prompt split over multiple lines The Ansible Lightspeed service reads the text, interacts with the IBM watsonx Code Assistant model, and generates the code recommendations. Prerequisites You meet one of the following requirements: Your organization has a trial or paid subscription to both the Red Hat Ansible Automation Platform and IBM watsonx Code Assistant. Your organization has a trial or paid subscription to the Red Hat Ansible Automation Platform, and you have a Red Hat Ansible Lightspeed trial account. You have installed and configured the Ansible VS Code extension . Procedure Log in to VS Code with your Red Hat account. Create a new YAML file or use an existing YAML file. Create a YAML file: Select File New Text File . From the lower right of the screen, click Plain Text , and in the language mode, select Ansible . Save the file as a YAML file format extension ( .yml or .yaml ). Use an existing YAML file: On the bottom right of the screen, click the existing language mode, and in the language mode settings, select Ansible . Note If you do not see the language mode section in your VS Code editor, from the Command Palette, select Configure Language Mode Ansible . Verify that you see an entry for Lightspeed on the status bar at the lower right of VS Code. If Ansible is already selected as the desired language but the Lightspeed entry is not displayed, re-select Ansible as the language mode. The following illustration shows Lightspeed entry on the VS Code status bar. Figure 4.3. Ansible and Lightspeed set as selected language mode Optional: If you see an error message about missing Ansible lint, you can install the missing module or disable it. Perform any one of the following tasks: Install Ansible lint: For installation information, see the Installing section of the Ansible Lint documentation. Disable Ansible lint: From the Activity bar, click the Extensions icon . From the Installed extensions list, select Ansible . From the Ansible extension page, click the Settings icon and select Extension Settings . Clear the Ansible › Validation › Lint: Enabled checkbox. Create a playbook or use an existing playbook. For more information, see the Getting started with playbooks guide. In the playbook, provide the following information to request multitask code recommendations: Start a new YAML file comment by entering a pound symbol (#) at the correct indentation. Add a detailed natural language prompt in a sequence, separating each task by using the ampersand symbol (&). Example of a multitask prompt For better readability, split your multitask inline prompts over multiple lines. To achieve this, end your current line with an ampersand symbol (&) and start the line with the hash symbol (#). Example of a multitask prompt split over multiple lines Press Enter directly after the task description. Keep the cursor at the same location in your file, and wait for the code recommendation results to populate. The Ansible Lightspeed service is engaged, and it starts generating code recommendations for multiple tasks. Important Ansible Lightspeed service takes around 5 seconds per task to populate the code recommendations. If you are using a multitask prompt, the Ansible Lightspeed service takes a bit longer (number of tasks times 5 seconds) to populate the results. Do not move your cursor or press any key while the code recommendation is being generated. If you change the cursor location or press any key, Ansible VS Code extension cancels the request and the Ansible Lightspeed service does not process your request. When the Ansible Lightspeed service is engaged, a Lightspeed processing status indicator is displayed in the lower right of the screen to denote that your code recommendation is being generated. Optional: If multitask code recommendations are not being generated, log out of VS Code and log in again using your Red Hat account. View your code recommendations and ensure that the recommendations match your task intent. The following illustration shows the code recommendations generated by the Ansible Lightspeed service for the multitask prompt Install postgresql-server & run postgresql-setup command : : Accept or reject the code recommendations: To accept a code recommendation, press Tab . To reject a code recommendation, press Esc . Note If you reject a recommendation, you can modify the prompt and review the generated code recommendations once again to match your task intent. On the ANSIBLE: LIGHTSPEED TRAINING MATCHES tab, view the content source matching results. The following illustration shows the training matches found in existing Ansible Galaxy content for the task prompt multitask prompt Install postgresql-server & run postgresql-setup command : Click Save to save the code recommendation changes in your Ansible YAML file. Additional resources Troubleshooting Ansible Visual Studio Code extension errors Troubleshooting Ansible code bot errors 4.3.4. Viewing the Ansible Lightspeed training matches The Red Hat Ansible Lightspeed with IBM watsonx Code Assistant machine learning model is trained on the following content: Existing public or private Git repositories Content from Ansible Galaxy Owing to IBM watsonx Code Assistant's generative AI technology, as well as the types of Ansible content that were used to train the model, it is not possible to identify the specific set of training data that contributed to the generated code recommendations. However, Ansible Lightspeed provides a capability that helps you to understand the possible origins of generated code recommendations. For each generated code recommendation, Red Hat Ansible Lightspeed lists the content source matches, including details such as potential source, content author, and relevant licenses. You can use this data to gain insight into potential training data sources used to generate the code recommendations. After you enter a natural language prompt in VS Code and see the generated code recommendations, you can view the content source matches on the ANSIBLE: LIGHTSPEED TRAINING MATCHES tab. For example, the following illustration shows the training matches for the multitask recommendation Install postgresql-server & run postgresql-setup command : Figure 4.4. Training matches for a multitask recommendation This capability enables you to find out the open source license terms that are associated with related training data. However, it is unlikely that either the training data used in fine-tuning the code or the output recommendations themselves are protected by

Commands:
Install postgresql-server & run postgresql-setup command
Create a keypair called lightspeed-keypair & create a vpc & create vpc_id var & create a security group that allows SSH & create subnet with 10.0.1.0/24 cidr & create an internet gateway & create a route table
Install postgresql-server & run postgresql-setup command
Create a keypair called lightspeed-keypair & create a vpc & create vpc_id var & create a security group that allows SSH & create subnet with 10.0.1.0/24 cidr & create an internet gateway & create a route table