Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Create an efficient Ansible development environment in VS Code

March 5, 2024
Nagesh Rathod
Related topics:
Automation and managementDeveloper toolsIDEs
Related products:
Podman DesktopRed Hat Ansible Automation Platform

    Ansible, a powerful automation tool, simplifies configuration management, application deployment, and infrastructure provisioning. When it comes to developing Ansible Playbooks and managing infrastructure, having a well-configured development environment can greatly enhance productivity. In this technical article, we will explore how to set up an Ansible development environment in the popular Visual Studio Code (VS Code) IDE.

    Prerequisites

    • Install Ansible Automation Platform
    • Install ansible-navigator on your system
    • Install Podman or Podman Desktop
    • Pulled down execution environment using Podman
    • Install Git 

    Why VS Code for Ansible Development Environment?

    The Ansible Language Server extension:

    • Provides syntax highlighting
    • Autocompletion (including with FQCN)
    • Easy jump to module code/documentation
    • Can leverage my execution environment

    Follow this blog for instructions on how to install ansible-navigator. When the installation is complete, make sure you have to pull one of the following images.

    podman pull  registry.redhat.io/ansible-automation-platform-22/ee-supported-rhel8:latest

    The above image requires a subscription on Ansible Automation Platform. Refer to the following article: How to install Microsoft SQL on RHEL using ansible-navigator

    podman pull quay.io/ansible/creator-ee:latest

    But this image is open to anyone. Like open source.

    You can use any image for your execution environment.

    Verify images are successfully pulled in your system using the following command.

    podman images

    Extension installation

    In the VS Code Extensions tab, search for and install Ansible as shown in Figure 1.

    extention install
    Figure 1: Installation of Ansible extensions.

    Ansible extension settings

    As part of the Ansible extension, several configuration options are available, including the ability to change the executable path for Ansible, Ansible lint, the Python interpreter, etc. Furthermore, users can choose the container engine, image name, pull policy, and more when enabling the automation execution environment. To see and change the configuration options in the VS Code window, go to Code -> Preference -> Settings and in the Search settings box type Ansible as shown in Figure 2.

    extention settings
    Figure 2: Setting up the extensions.

    It is possible to set preferences for a specific user or workspace, as well as remote types and workspace folders, depending on the environment. Settings in the user scope will be applied globally to any VS Code instance opened. Workspace scoped settings will be stored inside your workspace and only applied when the current workspace is opened. For more information, refer to the VS Code documentation here. You can also edit the .vscode/settings.json file within the workspace root folder to provide the Ansible settings for workspace settings. See Figure 3 below.

    settings file add
    Figure 3: Creating setting.json file.

    Activating and using Ansible extension

    As mentioned above, the vscode-ansible extension depends on the ansible-language-server running as a background process for features like auto-completion, hover, diagnostics, and go-to. In addition to auto-completion and diagnostics information for other related YAML files such as Ansible vars, ansible-navigator settings, ansible-galaxy requirements, ansible-lint configuration and other YAML files, this extension depends on the Red Hat vscode-yaml extension. The extension uses file pattern match to associate the file with the YAML language. 

    After activating the Ansible extension, you might notice issues like the extension not detecting Ansible Playbooks; instead it detects as yaml or yml format, which is totally fine. See Figure 4.

    yaml
    Figure 4: YAML file detected.

    In the bottom right corner, hover your cursor over the language (YAML in this case) to see Select Language Mode. When you click the language name (YAML), a drop-down menu will open; type Ansible into the tab and select it. After doing this, you will notice the identified language for the file is changed to Ansible, as shown in Figure 5.

    ansible identified
    Figure 5: Ansible file detected.

    The file identified as an Ansible language first time, the Ansible extension on VS Code will run the process in background to do auto-completion, hover, and diagnostics in the file as you type or hover within the file. The diagnostics information will be available in the PROBLEM tab which is beside the TERMINAL tab. After installation and once enabled, the language server will run ansible-lint by default to generate diagnostics information on the open file. If ansible-lint is not installed, the server will run ansible-playbook–syntax-check to generate diagnostics information

    Before changing the above setting to every file, set it for all files by clicking on Code -> Preferences -> Settings and typing file associations in the search box. Add the items in extension with the language type as shown in Figure 6.

    add yaml as ansible
    Figure 6: Adding YAML/YML file as Ansible file.

    Using automation execution environments

    To see the automation execution environments supported by extension, you can go to settings (Code -> Preferences -> Settings) and type ansible.execution environment. This is shown in Figure 7.

    extention settings add
    Figure 7: Check Execution Environment settings.

    After enabling the execution environment (EE), the extension will pull the quay.io/ansible/creator-ee:latest image by default, if it is not present locally. The value of the image can be changed by providing the intended value for ansible.executionEnvironment.image setting. After the EE pull is successful, the Ansible extension will copy the plug-in's docs from within EE to the local cache folder, and it will be used to provide auto-completion, hover and go to functionality. Since the creator-ee image has ansible-lint bundled, the Ansible extension and ansible-language-server will volume mount the entire workspace within the EE and run ansible-lint or ansible-playbook—syntax-check based on settings to provide diagnostics information in editor. This process is shown in Figure 8.

    ansible output window
    Figure 8: Execution Environment logs on OUTPUT tab.

    The auto-completions will now provide suggestions for plugins that are part of the given execution environment image name, as depicted in Figure 9.

    auto completion
    Figure 9: Auto completion suggestion.

    Ansible Playbook run entry point

    The extension also provides an option to run an Ansible Playbook from within the extension, either using ansible-navigator run or ansible-playbook command as shown in the below snapshot (Figure 10).

    run playbook with option
    Figure 10: Run Playbook with options.

    Log extraction

    The Ansible Playbook logs are collected in the same directory where you keep the playbooks. You have to run the playbook with ansible-navigator, so only the logs file will generate. This is shown in Figure 11. The generated file will be in the following format:

    <playbook>-artifact-<Date>-<time>.json
    log file
    Figure 11: Log file generator after job execution.

    Continue your automation journey with Ansible Automation Platform

    Get started with Ansible Automation Platform by exploring interactive hands-on labs. Download Ansible Automation Platform at no cost and begin your automation journey. 

    Last updated: December 5, 2024

    Related Posts

    • How to create execution environments using ansible-builder

    • Introducing Ansible Molecule with Ansible Automation Platform

    • How to deploy applications using Ansible Automation Platform

    • How to install Red Hat Ansible Automation Platform on RHEL 9

    • Get started with the Wildfly collection

    • How Ansible lint improves playbook debugging

    Recent Posts

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    • Deploy with confidence: Continuous integration and continuous delivery for agentic AI

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    What’s up next?

    Get a preview of the Red Hat Certified Engineer (RHCE) Ansible Automation Study Guide (O’Reilly), which covers key Ansible concepts for your system administration needs.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.