Bookmark this page

Guided Exercise: Preparing for Ansible Development

Install automation content navigator on a control node that runs Red Hat Enterprise Linux.

Outcomes

  • Prepare the workstation machine to run playbooks by using an automation execution environment with the ansible-navigator command.

  • Examine Visual Studio Code settings.

  • Use automation content navigator to run a playbook.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.

[student@workstation ~]$ lab start intro-prepare

Instructions

Install development tools for Red Hat Ansible Automation Platform on workstation, which runs Red Hat Enterprise Linux.

A code editor, Visual Studio Code (VS Code), has already been installed. You use it in this course to perform various actions that you could also complete from the command line. These actions include viewing files, editing files, cloning Git repositories, committing and pushing changes to Git repositories, and running automation content navigator.

Test the development tools by using VS Code to run a test Ansible Playbook.

  1. Install software that you use throughout the course.

    1. Check your system for the ansible-core, ansible-navigator, ansible-lint, and podman RPM packages.

      [student@workstation ~]$ sudo dnf list ansible-core ansible-navigator \
      ansible-lint podman
      [sudo] password for student: student
      Red Hat Enterprise Linux 9 for x86_64 - BaseOS (RPMs)  100 kB/s | 4.1 kB     ...
      Red Hat Enterprise Linux 9 for x86_64 - AppStream (RPM 134 kB/s | 4.5 kB     ...
      Installed Packages
      ansible-core.x86_64      2.14.4-1.el9ap   @ansible-automation-platform-2.3-fo...
      podman.x86_64            2:4.2.0-11.el9_1 @rhel-9-for-x86_64-appstream-rpms
      Available Packages
      ansible-lint.noarch      6.8.2-1.el9ap    ansible-automation-platform-2.3-for...
      ansible-navigator.noarch 2.2.0-1.el9ap    ansible-automation-platform-2.3-for...
    2. The ansible-core and podman packages are already installed. Install the ansible-navigator and ansible-lint packages.

      [student@workstation ~]$ sudo dnf install ansible-navigator ansible-lint
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
      Complete!
  2. Download the hub.lab.example.com/ee-supported-rhel8 automation execution environment from the lab environment's private automation hub. Automation content navigator uses it to run the Ansible Playbook.

    1. Use the podman login command to log in to the classroom private automation hub at hub.lab.example.com. Use student as your username and redhat123 as your password.

      [student@workstation ~]$ podman login hub.lab.example.com
      Username: student
      Password: redhat123
      Login Succeeded!
    2. Use the podman pull command to download the automation execution environment.

      [student@workstation ~]$ podman pull hub.lab.example.com/ee-supported-rhel8
      Trying to pull hub.lab.example.com/ee-supported-rhel8:latest...
      Getting image source signatures
      Copying blob 9d6b728989c4 done
      Copying blob a94bd44d2f55 done
      Copying blob c7e856e03741 done
      Copying blob 8b41bcf810f7 done
      Copying config 024856bccc done
      Writing manifest to image destination
      Storing signatures
      024856bccc5fbafddc07cbf758adf1e42d041f478a7c14427b2ca4a9b84294f3
  3. Examine VS Code settings. Confirm that the Ansible extension is installed.

    1. Open VS Code. Click Activities on the top bar, type code in the Type to search field, and press Enter or click the Visual Studio Code icon.

      Figure 1.12: Searching for VS Code
    2. Navigate to ViewExtensions to display a list of installed and recommended extensions. Notice that the Ansible extension has been installed in the lab environment.

    3. Click any extension, such as the Ansible extension, to display details about the extension. You can enable or disable an installed extension. You can uninstall or install another version of an extension.

      Important

      Do not uninstall the Ansible extension. If your lab environment does not provide outside internet access, then you cannot reinstall the extension.

    4. You can adjust the settings for installed extensions. To adjust the settings for the Ansible extension, click the Manage icon and then click Extension Settings.

      Figure 1.13: VS Code extension settings for Ansible

      Extension settings are a subset of all VS Code settings. You can access all VS Code settings by clearing the filter, such as the @ext:redhat.ansible filter, or by closing the Settings tab and then navigating to FilePreferencesSettings.

      You can enable or disable the Auto Save setting directly from the File menu.

    5. (Optional) Adjust VS Code settings for your preferences, such as enabling the auto save feature and changing the font size.

    6. Close the Settings tab and any other tabs that you opened.

  4. From within VS Code, open the /home/student/intro-prepare directory and view the sample.yml playbook.

    1. Navigate to ViewExplorer and then navigate to FileOpen Folder.

      Important

      If navigating to FileOpen Folder does not appear to do anything, then VS Code probably opened the Open Folder window behind the current window. Click the date and time in the top bar and then click the Visual Studio Code notification.

      Figure 1.14: VS Code open folder notification
    2. Navigate to Homeintro-prepare and then click Open.

      The first time you open a folder, VS Code displays a window asking if you trust the authors of the files in the folder. Select Trust the authors of all files in the parent folder 'student' and then click Yes, I trust the authors.

      Figure 1.15: Trusting the authors of files in VS Code
    3. Click the sample.yml playbook. As soon as you open the file, VS Code uses the ansible-lint command to check the playbook for errors. The lower left corner of the application displays the result of these checks. The sample.yml playbook does not produce any errors or warnings.

      Figure 1.16: Bottom bar of VS Code
  5. Run the sample.yml playbook. You can either run the playbook from a GNOME terminal or from a VS Code terminal.

    1. To use a VS Code terminal, navigate to TerminalNew Terminal.

      Important

      Red Hat Enterprise Linux 9 updated the default SELinux policy to disallow commands with text relocation libraries. Because of this change, opening a VS Code terminal generates an SELinux security alert. Note that this policy change does not affect the GNOME terminal.

      If you are quick enough, then you can click Show as soon as you see the SELinux alert notification. Otherwise, you can access the notification by clicking the date and time in the top bar and clicking New SELinux security alert.

      Figure 1.17: SELinux security alert

      You can safely ignore this alert. From the SELinux Alert Browser window, click Ignore and then close the alert browser window.

      More information about this security enhancement can be found by searching for BZ#2055822 at: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/9.0_release_notes/index#enhancement_security

    2. Use the ansible-navigator run command to run the sample.yml playbook. The playbook displays your configured VS Code settings. Your settings might be different from the following output.

      [student@workstation intro-prepare]$ ansible-navigator run sample.yml -m stdout
      ...output omitted...
      TASK [Display /home/student/.config/Code/User/settings.json] *******************
      ok: [workstation] => {
          "slurp_settings['content'] | b64decode": {
              "editor.fontSize": 11,
              "files.autoSave": "afterDelay",
              "redhat.telemetry.enabled": false
          }
      }
      
      PLAY RECAP *********************************************************************
      workstation                : ok=3    changed=0    unreachable=0    failed=0  ...
    3. Close the sample.yml tab.

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish intro-prepare

Revision: do457-2.3-7cfa22a