Search

Chapter 3. Installing Ansible development tools

download PDF

Red Hat provides two options for installing Ansible development tools.

  • Installation on a RHEL container running inside VS Code. You can install this option on MacOS, Windows, and Linux systems.
  • Installation on your local RHEL system using an RPM (Red Hat Package Manager) package.

3.1. Requirements

To install and use Ansible development tools, you must meet the following requirements. Extra requirements for Windows installations and containerized installations are indicated in the procedures.

3.1.1. Requirements for Ansible development tools on Windows

If you are installing Ansible development tools on a container in VS Code on Windows, there are extra requirements:

  • Windows Subsystem for Linux(WSL2)
  • Podman Desktop

3.1.1.1. Installing WSL

  1. Install WSL2 without a distribution:

    $ `wsl --install --no-distribution`
  2. Use cgroupsv2 by disabling cgroupsv1 for WSL2:

    Edit the %USERPROFILE%/wsl.conf file and add the following lines to force cgroupv2 usage:

    [wsl2]
    kernelCommandLine = cgroup_no_v1="all"

3.1.1.2. Installing Podman Desktop on a Windows machine

  1. Install Podman Desktop. Follow the instructions in Installing Podman Desktop and Podman on Windows in the Podman Desktop documentation.

    You do not need to change the default settings in the set-up wizard.

  2. Ensure the podman machine is using cgroupsv2:

    $ podman info | findstr cgroup
  3. Test Podman Desktop:

    $ podman run hello

3.1.1.3. Configuring settings for Podman Desktop

  1. Add a %USERPROFILE%\bin\docker.bat file with the following content:

    @echo off
    podman %*

    This avoids having to install Docker as required by the VS Code Dev Container extension.

  2. Add the %USERPROFILE%\bin directory to the PATH.

    1. Select Settings and search for "Edit environment variables for your account" to display all of the user environment variables.
    2. Highlight "Path" in the top user variables box, click Edit and add the path.
    3. Click Save to set the path for any new console that you open.

3.1.2. Authenticating with the Red Hat container registry

All container images available through the Red Hat container catalog are hosted on an image registry, registry.redhat.io. The registry requires authentication for access to images.

To use the registry.redhat.io registry, you must have a Red Hat login. This is the same account that you use to log in to the Red Hat Customer Portal (access.redhat.com) and manage your Red Hat subscriptions.

Note

If you are planning to install the Ansible development tools on a container inside VS Code, you must log in to registry.redhat.io before launching VS Code so that VS Code can pull the devtools container from registry.redhat.io.

If you are running Ansible development tools on a container inside VS Code and you want to pull execution environments or the devcontainer to use as an execution environment, you must log in from a terminal prompt within the devcontainer from a terminal inside VS Code.

You can use the podman login or docker login commands with your credentials to access content on the registry.

Podman
$ podman login registry.redhat.io
Username: my__redhat_username
Password: ***********
Docker
$ docker login registry.redhat.io
Username: my__redhat_username
Password: ***********

For more information about Red Hat container registry authentication, see Red Hat Container Registry Authentication on the Red Hat customer portal.

3.1.3. Installing VS Code

3.1.4. Installing the VS Code Ansible extension

The Ansible extension adds language support for Ansible to VS Code. It incorporates Ansible development tools to facilitate creating and running automation content.

For a full description of the Ansible extension, see the Visual Studio Code Marketplace.

See Learning path - Getting Started with the Ansible VS Code Extension for tutorials on working with the extension.

To install the Ansible VS Code extension:

  1. Open VS Code.
  2. Click the Extensions ( Extensions ) icon in the Activity Bar, or click View Extensions, to display the Extensions view.
  3. In the search field in the Extensions view, type Ansible Red Hat.
  4. Select the Ansible extension and click Install.

When the language for a file is recognized as Ansible, the Ansible extension provides features such as auto-completion, hover, diagnostics, and goto. The language identified for a file is displayed in the Status bar at the bottom of the VS Code window.

The following files are assigned the Ansible language:

  • YAML files in a /playbooks directory
  • Files with the following double extension: .ansible.yml or .ansible.yaml
  • Certain YAML names recognized by Ansible, for example site.yml or site.yaml
  • YAML files whose filename contains "playbook": playbook.yml or playbook.yaml

If the extension does not identify the language for your playbook files as Ansible, follow the procedure in Associating the Ansible language to YAML files.

3.1.5. Configuring Ansible extension settings

The Ansible extension supports multiple configuration options.

You can configure the settings for the extension on a user level, on a workspace level, or for a particular directory. User-based settings are applied globally for any instance of VS Code that is opened. Workspace settings are stored within your workspace and only apply when the current workspace is opened.

It is useful to configure settings for your workspace for the following reasons:

  • If you define and maintain configurations specific to your playbook project, you can customize your Ansible development environment for individual projects without altering your preferred setup for other work. You can have different settings for a Python project, an Ansible project, and a C++ project, each optimized for the respective stack without the need to manually reconfigure settings each time you switch projects.
  • If you include workspace settings when setting up version control for a project you want to share with your team, everyone uses the same configuration for that project.

Procedure

  1. Open the Ansible extension settings:

    1. Click the 'Extensions' icon in the activity bar.
    2. Select the Ansible extension, and click the 'gear' icon and then Extension Settings to display the extension settings.

      Alternatively, click Code Settings Settings to open the Settings page.

    3. Enter Ansible in the search bar to display the settings for the extension.
  2. Select the Workspace tab to configure your settings for the current VS Code workspace.
  3. The Ansible extension settings are pre-populated. Modify the settings to suit your requirements:

    • Check the Ansible Validation Lint: Enabled box to enable ansible-lint.
    • Check the Ansible Execution Environment: Enabled box to use an execution environment.
    • Specify the execution environment image you want to use in the Ansible > Execution Environment: image field.
    • To use Red Hat Ansible Lightspeed, check the Ansible > Lightspeed: Enabled box, and enter the URL for Lightspeed.

The settings are documented on the Ansible VS Code Extension by Red Hat page in the VisualStudio marketplace documentation.

3.1.6. Associating the Ansible language to YAML files

The Ansible VS Code extension works only when the language associated with a file is set to Ansible. The extension provides features that help create Ansible playbooks, such as auto-completion, hover, and diagnostics.

The Ansible VS Code extension automatically associates the Ansible language with some files. The procedures below describe how to set the language for files that are not recognized as Ansible files.

Manually associating the Ansible language to YAML files

The following procedure describes how to manually assign the Ansible language to a YAML file that is open in VS Code.

  1. Open or create a YAML file in VS Code.
  2. Hover the cursor over the language identified in the status bar at the bottom of the VS Code window to open the Select Language Mode list.
  3. Select Ansible in the list.

    The language shown in the status bar at the bottom of the VS Code window for the file is changed to Ansible.

Adding persistent file association for the Ansible language to settings.json

Alternatively, you can add file association for the Ansible language in your settings.json file.

  1. Open the settings.json file:

    1. Click View Command Palette to open the command palette.
    2. Enter Workspace settings in the search box and select Open Workspace Settings (JSON).
  2. Add the following code to settings.json.

    {
      ...
    
      "files.associations": {
        "*plays.yml": "ansible",
        "*init.yml": "yaml",
      }
    }

3.1.7. Installing and configuring the Dev Containers extension

If you are installing the containerized version of Ansible development tools, you must install the Microsoft Dev Containers extension in VS Code.

  1. Open VS Code.
  2. Click the Extensions ( Extensions ) icon in the Activity Bar, or click View Extensions, to display the Extensions view.
  3. In the search field in the Extensions view, type Dev Containers.
  4. Select the Dev Containers extension from Microsoft and click Install.

If you are using Podman or Podman Desktop as your containerization platform, you must modify the default settings in the Dev Containers extension.

  1. Replace docker with podman in the Dev Containers extension settings:

    1. In VS Code, open the settings editor.
    2. Search for @ext:ms-vscode-remote.remote-containers.

      Alternatively, click the Extensions icon in the activity bar and click the gear icon for the Dev Containers extension.

  2. Set Dev > Containers:Docker Path to podman.
  3. Set Dev > Containers:Docker Compose Path to podman-compose.

3.2. Installing Ansible development tools on a container inside VS Code

The Dev Containers VS Code extension requires a .devcontainer file to store settings for your dev containers. You must create a config file for your dev container and reopen your directory in a container in VS Code.

Prerequisites

  • You have installed a containerization platform, for example Podman, Podman Desktop, Docker, or Docker Desktop.
  • You have a Red Hat login and you have logged in to the Red Hat registry at registry.redhat.io. For information about logging in to registry.redhat.io, see Authenticating with the Red Hat container registry.
  • You have installed VS Code.
  • You have installed the Ansible extension in VS Code.
  • You have installed the Microsoft Dev Containers extension in VS Code.
  • If you are installing Ansible development tools on Windows, launch VS Code and connect to the WSL machine:

    1. Click the Remote ( Remote ) icon.
    2. In the dropdown menu that appears, select the option to connect to the WSL machine.

Procedure

  1. In VS Code, open the directory where you want to store the configuration files for your development container.
  2. Create a subdirectory called .devcontainer.
  3. In the .devcontainer directory, create a file called devcontainer.json.

    You must use different settings depending on whether you are using Podman or Docker.

    • If you are using Podman or Podman desktop, add the following text to devcontainer.json:

      {
        "name": "ansible-dev-container-podman",
        "image": "registry.redhat.io/ansible-automation-platform-25/ansible-dev-tools-rhel8:latest",
        "containerUser": "root",
        "runArgs": [
          "--cap-add=CAP_MKNOD",
          "--cap-add=NET_ADMIN",
          "--cap-add=SYS_ADMIN",
          "--cap-add=SYS_RESOURCE",
          "--device",
          "/dev/fuse",
          "--security-opt",
          "seccomp=unconfined",
          "--security-opt",
          "label=disable",
          "--security-opt",
          "apparmor=unconfined",
          "--security-opt",
          "unmask=/sys/fs/cgroup",
          "--userns=host",
          "--hostname=ansible-dev-container"
        ],
        "customizations": {
          "vscode": {
            "extensions": ["redhat.ansible"]
          }
        }
      }
    • If you are using Docker or Docker desktop, add the following text to devcontainer.json:

      {
        "name": "ansible-dev-container-docker",
        "image": "registry.redhat.io/ansible-automation-platform-25/ansible-dev-tools-rhel8:latest",
        "containerUser": "root",
        "runArgs": [
          "--privileged",
          "--device",
          "/dev/fuse",
          "--hostname=ansible-dev-container"
        ],
        "updateRemoteUserUID": true,
        "customizations": {
          "vscode": {
            "extensions": ["redhat.ansible"]
          }
        }
      }
  4. Reopen the directory in a container.

    • If VS Code detects that your directory contains the devcontainer.json file, the following notification appears:

      Reopen in container

      Click Reopen in Container.

    • If the notification does not appear, click the Remote ( Remote ) icon. In the dropdown menu that appears, select Reopen in Container.

The Remote () status in the VS Code Status bar displays opening Remote and a notification indicates the progress in opening the container.

Verification

When the directory reopens in a container, the Remote () status displays Dev Container: ansible-dev-container.

Note

The base image for the container is a Universal Base Image Minimal (UBI Minimal) image that uses microdnf as a package manager. The dnf and yum package managers are not available in the container.

For information about using microdnf in containers based on UBI Minimal images, see Adding software in a minimal UBI container in the Red Hat Enterprise Linux Building, running, and managing containers guide.

3.3. Installing Ansible development tools from a package on RHEL

Ansible development tools is bundled in the Ansible Automation Platform RPM (Red Hat Package Manager) package. Refer to the RPM installation documentation for information on installing Ansible Automation Platform.

Prerequisites

  • You have installed RHEL.
  • You have registered your system with Red Hat Subscription Manager.
  • You have installed a containerization platform, for example Podman or Docker.

Procedure

  1. Run the following command to check whether Simple Content Access (SCA) is enabled:

    $ su subscription-manager status

    If Simple Content Access is enabled, the output contains the following message:

    Content Access Mode is set to Simple Content Access.
    1. If Simple Content Access is not enabled, attach the Red Hat Ansible Automation Platform SKU:

      $ subscription-manager attach --pool=<sku-pool-id>
  2. Install Ansible development tools with the following command:

    $ sudo dnf install --enablerepo=ansible-automation-platform-2.4-for-rhel-8-x86_64-rpms ansible-dev-tools
    $ sudo dnf install --enablerepo=ansible-automation-platform-2.4-for-rhel-9-x86_64-rpms ansible-dev-tools

Verification:

Verify that the Ansible development tools components have been installed:

$ rpm -aq | grep ansible

The output displays the Ansible packages that are installed:

ansible-sign-0.1.1-2.el9ap.noarch
ansible-creator-24.4.1-1.el9ap.noarch
python3.11-ansible-runner-2.4.0-0.1.20240412.git764790f.el9ap.noarch
ansible-runner-2.4.0-0.1.20240412.git764790f.el9ap.noarch
ansible-builder-3.1.0-0.2.20240413.git167ed5c.el9ap.noarch
ansible-dev-environment-24.1.0-2.el9ap.noarch
ansible-core-2.16.6-0.1.20240413.gite636132.el9ap.noarch
python3.11-ansible-compat-4.1.11-2.el9ap.noarch
python3.11-pytest-ansible-24.1.2-1.el9ap.noarch
ansible-lint-6.14.3-4.el9ap.noarch
ansible-navigator-3.4.1-2.el9ap.noarch
python3.11-tox-ansible-24.2.0-1.el9ap.noarch
ansible-dev-tools-2.5-2.el9ap.noarch

On successful installation, you can view the help documentation for ansible-creator:

$ ansible-creator --help

usage: ansible-creator [-h] [--version] command ...

The fastest way to generate all your ansible content.

Positional arguments:
 command
  add           Add resources to an existing Ansible project.
  init          Initialize a new Ansible project.

Options:
 --version      Print ansible-creator version and exit.
 -h     --help  Show this help message and exit
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.