Ansible VS Code ExtensionThe Ansible extension for Visual Studio Code streamlines Ansible development by providing an integrated, feature-rich environment tailored for automation workflows. It offers features such as syntax highlighting, linting, intelligent code completion, and AI-assisted suggestions via Ansible Lightspeed. With support for multi-root workspaces, containerized execution environments, and extensive configuration options, the extension enhances productivity and ensures consistent code quality for both individual and team-based projects. This extension adds language support for Ansible in Visual Studio Code and OpenVSX by using the ansible-language-server. Installation RequirementsBefore you begin, make sure your system has:
Manual Extension ActivationIt is recommended to open a folder containing Ansible files with a VS Code workspace. Note:
Getting StartedWelcome PageThe extension provides a comprehensive Welcome Page that serves as a dashboard for Ansible development tools. Access it as follows:
Interactive WalkthroughsThe extension offers guided walkthroughs to help you quickly get started with Ansible development using step-by-step instructions. Create an Ansible EnvironmentLearn how to create a new Ansible playbook, configure the environment using the status bar, and install the necessary Ansible packages to get set up. Start Automating with Your First Ansible PlaybookThis walkthrough guides you through enabling Ansible Lightspeed, creating a playbook project, writing your first playbook, and saving it within the project structure. Discover Ansible Development ToolsExplore the full range of Ansible development tools available in the extension, including scaffolding content, testing, and deployment guidance for your automation journey. Quick LinksThe Quick Links panel provides easy access to common Ansible tasks and is available in the Ansible sidebar view. It can be accessed by clicking on the Ansible extension icon and includes: Launch SectionThis section provides quick access to:
Initialize SectionThis section helps you create new Ansible projects:
Add SectionThis section allows you to add resources to existing projects:
Using Dev ContainersThis extension supports generating dev containers to provide isolated, consistent Ansible development environments in VS Code. The Microsoft Dev Containers extension is required for this feature. See the Ansible Development Tools (ADT)- Execution Environment documentation for more information on what is included in the generated dev container. Create a dev containerQuick Links Panel: Go to Ansible sidebar → click dev container Command Palette: Ctrl+Shift+P → search "Ansible: Create a dev container" Configuration OptionsChoose image:
Set destination and overwrite options in the webview, and click "Create". Open workspace in the dev containerCommand Palette: Ctrl+Shift+P → search "Dev Containers: Reopen in container" Select the dev container file that matches your desired container engine. The workspace will reopen in a container with all the Ansible Development Tools (ADT) installed. Ansible LightspeedThe extension integrates with Ansible Lightspeed with watsonx Code Assistant to provide AI-powered features. Lightspeed provides inline code suggestions as you type:
See the Red Hat Ansible Lightspeed setup guide to get started. Content Creation ToolsThe extension provides webview-based interfaces for creating and scaffolding Ansible content. Creating CollectionsYou can create a new Ansible collection with a structured layout including:
To create a collection:
Creating PlaybooksThe extension offers multiple ways to create playbooks: Empty Playbook
AI-Generated Playbook (with Ansible Lightspeed)
Playbook Project
A complete project structure will be created with playbooks, inventory, and configuration files Creating Execution EnvironmentsYou can create execution environment configurations for containerized Ansible environments:
Ansible Language FilesThe extension works when a document is assigned the Ansible language. Files are automatically recognized as 'Ansible' in these cases: Without file inspection
Additionally, in VS Code, you can add persistent file association for language
to
File inspection for Ansible keywords
Modelines (optional)
Rest all the .yml, or .yaml files will remain yaml by default unless the user explicitly changes the language to ansible for which the process is mentioned below. Ansible Language FeaturesSyntax highlightingThe extension provides distinct highlighting for:
ValidationWhile you type, the syntax of your Ansible scripts is verified and any feedback is provided instantaneously. Integration with ansible-lintOn opening and saving a document, Smart autocompletionThe extension tries to detect whether the cursor is on a play, block or task etc. and provides suggestions accordingly. There are also a few other rules that improve user experience:
Auto-closing Jinja expressionsWhen writing a Jinja expression, you only need to type Documentation referenceDocumentation is available on hover for Ansible keywords, modules and module
options. The extension works on the same principle as Jump to module codeYou may also open the implementation of any module using the standard Go to
Definition operation, for instance, by clicking on the module name while
holding Data and TelemetryThe Known limitations
ContactWe welcome your feedback, questions and ideas. Learn how to contact the Ansible VS Code team. CreditBased on the good work done by Tomasz Maciążek |