Streamline automation in OpenShift Dev Spaces with Ansible

In the ever-evolving landscape of software development, the quest for streamlined workflows and increased productivity is constant. This learning path, created by Valerii Svydenko, will guide you through the symbiotic relationship between Red Hat OpenShift Dev Spaces and Ansible, unlocking a realm where efficiency reigns supreme. You'll delve into the seamless integration of OpenShift Dev Spaces and Ansible, where each element complements the other in perfect harmony. OpenShift Dev Spaces, which provides isolated and tailored development environments, meets Ansible, the powerful automation tool. The result is a synergy that transforms the way we approach developing and testing Ansible automation.

Our first step in exploring the seamless integration of Red Hat OpenShift Dev Spaces and Ansible is to access OpenShift Dev Spaces.

To access OpenShift Dev Spaces, go to this workspace URL, which will redirect you to the user dashboard for OpenShift Dev Spaces (Figure 1).

The user dashboard of Red Hat OpenShift Dev Spaces.
Figure 1: The user dashboard of Red Hat OpenShift Dev Spaces.

Start a workspace

From the user dashboard, select the Create Workspace tab and input the following URL into the Git Repo URL field: https://github.com/redhat-developer-demos/ansible-devspaces-demo. Then select Create & Open (Figure 2).

Paste the repo URL to the Git Repo URL field then select the Create & Open.
Figure 2: Put the repository in the Git Repo URL field and select Create and Open.

During the workspace startup, you will be asked to authorize the GitHub OAuth app configured for each of the Developer Sandbox clusters (Figure 3).

You will be asked to authorize the GitHub OAuth app configured for each of the Developer Sandbox clusters.
Figure 3: Authorize the GitHub OAuth app for each of the clusters.

Authorization allows users full GitHub access from the workspaces to execute commands like git push without any setup. Under the hood, once the permissions are granted, the git-credentials-secret is created in the user namespace, which stores the token used by OpenShift Dev Spaces (Figure 4).

Note: You can revoke access at any time by selecting User Preferences -> Git Services from the user dashboard or revoking it directly from the GitHub settings.

Revoke the access at any time by selecting User Preferences then Git Services on the user dashboard or directly from the GitHub settings.
Figure 4: Revoke access on the User Dashboard or directly from the GitHub settings.

Once you have started the workspace, you will be able to see the source code of the application you are going to work with (Figure 5).

Once the workspace is started, you will see the source code of the application we are going to work with,
Figure 5: The workspace displays the source code of the application.

The workspace contains not only the source code, but also the runtime that lets you instantly start coding and provides the development environment for the following:

  • Ansible playbook creation
  • Testing with Molecule
  • ansible-navigator
  • ansible-lint checks

Repeatable and fast development environments are the major benefits of the Red Hat OpenShift Dev Spaces. You can use the workspace you create to immediately start working on your Ansible projects without worrying about manually setting up your local development environment. 

With OpenShift Dev Spaces, your development environment–including the commands for running the full Molecule test scenario or each stage one by one–is defined in a declarative way using the devfile.yaml in the root of the repository (Figure 6).

The development environment, including the commands for running the full Molecule test scenario or each stage one by one, is defined in a declarative way using the devfile.yaml in the root of the repository.
Figure 6: The development environment is defined in a declarative way using the devfile.yaml.

Devfile is a Cloud Native Computing Foundation (CNCF) sandbox project that provides an open standard, which defines containerized development environments. Learn more about Devfile from the official documentation.

OpenShift Dev Spaces supplies a VS Code-like editing experience that many developers find productive. It is highly configurable with an extension library that supports any development workflow. The Ansible VS Code extension is present in the workspace, which allows for instant syntax checking, linting, and autocomplete to accelerate development. Because the workspace also provides Python language support, YAML, and OpenShift Toolkit extensions, you can add additional extensions for GitHub pull request support or any other extension published on the Open VSX Registry (Figure 7).

Dev Spaces supplies a VS Code-like editing experience that is highly configurable, with an extension library to support any development workflow.
Figure 7: Dev Spaces supplies a VS Code-like editing experience that is highly configurable, with an extension library to support any development workflow.

Congratulations! You have started a workspace. Your second step in your journey through OpenShift Dev Spaces and Ansible is to test a sample Ansible role.

Previous resource
Overview: Streamline automation in OpenShift Dev Spaces with Ansible
Next resource
Test a sample Ansible role using Molecule

Info alert: Streamline automation in OpenShift Dev Spaces with Ansible

In the ever-evolving landscape of software development, the quest for streamlined workflows and increased productivity is constant. This learning path, created by Valerii Svydenko, will guide you through the symbiotic relationship between Red Hat OpenShift Dev Spaces and Ansible, unlocking a realm where efficiency reigns supreme.

You'll delve into the seamless integration of OpenShift Dev Spaces and Ansible, where each element complements the other in perfect harmony. OpenShift Dev Spaces, which provides isolated and tailored development environments, meets Ansible, the powerful automation tool. The result is a synergy that transforms the way we approach developing and testing Ansible automation.