Chapter 4. Developing automation content in your workspace
The Ansible development tools are installed as part of the Ansible extension in the Ansible development workspace. You can use Ansible development tools to scaffold directories for automation content in your repository.
Using the Ansible extension ensures that best practices for directory structure are met. For more information about using the Ansible extension to develop automation content, refer to Developing automation content.
Red Hat recommends that you create only one collection per repository, so that each collection has a clear, specific purpose. This approach promotes reusability, as each collection is a self-contained unit of content. A one-to-one relationship between a collection and its repository also improves manageability by simplifying dependency management, maintenance, and release cycles.
4.1. Creating collections and playbooks in your Ansible development workspace Copy linkLink copied to clipboard!
Use the Ansible extension in VS Code to use Ansible development tools to scaffold directories and files for your automation content. You can use Red Hat Ansible Lightspeed with IBM watsonx Code Assistant to help you write playbooks, and ansible-lint to debug them.
Procedure
- In the OpenShift Dev Spaces dashboard. select the Ansible development workspace where you want to develop automation content.
- In the Activity bar of VS Code, select the Ansible icon to open Ansible development tools.
- Select Connect in the Ansible Lightspeed section to log in to Ansible Lightspeed.
Select an option in the initialize section of Ansible Development tools to scaffold files and directories for a collection project or a playbook project.
- For more information on creating a playbook project, see the Scaffolding a playbook project chapter of the Developing automation content guide.
- For more information on creating a roles collection project, see the Scaffolding a collection project for your roles section of the Developing automation content guide.
- Select options in the Add section of Ansible development tools to add files for playbooks or roles to your project. Alternatively, you can use the options in the Ansible Lightspeed section to generate playbooks or roles.
Save your work:
-
Click the main menu icon in the Activity bar and select
. -
Use
git addandgit commitcommands to stage the changed files and commit your changes to the local repository in the workspace. -
Use the
git pushcommand to push your updates to your repository in your source control manager.
-
Click the main menu icon in the Activity bar and select
4.2. Editing and debugging automation content in your Ansible development workspace Copy linkLink copied to clipboard!
You can continue your work in a previously created workspace. Workspaces that have been inactive for a set period might be paused to free up resources. The duration of inactivity before timeout is configured in OpenShift Dev Spaces by your administrator. A paused workspace automatically relaunches when you select it from the OpenShift Dev Spaces dashboard.
Ansible lint indicates errors in your playbooks.
Procedure
- To display your previously created workspaces, select Workspaces in your OpenShift Dev Spaces dashboard.
- Select Open next to the workspace that you want to use.
- Select the Explorer icon in the Activity bar to open the file explorer, and open the file you want to edit.
- While you are editing, the Ansible extension provides suggestions. Select a suggestion from the dropdown list to include it in your playbook.
- To view documentation for a keyword or a module, hover your mouse over it.
-
Open the terminal in VS Code: click the main menu icon in the Activity bar and select
. Select the Problems tab in the terminal to view issues that
ansible-linthas identified.In the following example, one error is selected in the Problems tab, and the corresponding line in the playbook is highlighted.
- When you have resolved the problems in your playbook, a message is displayed in the Problems tab of the terminal.
4.3. Executing playbooks in your Ansible development workspace Copy linkLink copied to clipboard!
You can execute a playbook using the Ansible extension in VS Code.
Procedure
-
To execute a playbook in your Ansible development workspace, right-click on a playbook name in the file explorer and select
.
You cannot use execution environments in Ansible development workspaces. Do not use ansible-navigator to execute playbooks.