Install and configure VS Code
Install VS Code by following the instructions found on the Download Visual Studio Code page in the official documentation.
About this task Copy linkLink copied!
Procedure Copy linkLink copied!
Install the VS Code Ansible extension Copy linkLink copied!
The Ansible extension adds language support for Ansible to VS Code. It incorporates Ansible development tools to facilitate creating and running automation content.
About this task Copy linkLink copied!
For a full description of the Ansible extension, see the Visual Studio Code Marketplace.
Procedure Copy linkLink copied!
- Open VS Code.
- Click the Extensions (
) icon in the Activity Bar, or click , to display the Extensions view. - In the search field in the Extensions view, type
Ansible Red Hat. - Select the Ansible extension and click .
Results Copy linkLink copied!
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
/playbooksdirectory - Files with the following double extension:
.ansible.ymlor.ansible.yaml - Certain YAML names recognized by Ansible, for example
site.ymlorsite.yaml - YAML files whose filename contains "playbook":
playbook.ymlorplaybook.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.
Configure Ansible extension settings Copy linkLink copied!
The Ansible extension supports multiple configuration options.
Before you begin Copy linkLink copied!
- Open a workspace or folder, or create a new folder, in VS Code using the menu. This is necessary because the file that stores settings preferences for workspaces is specific to a folder or workspace.
About this task Copy linkLink copied!
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. A VS Code workspace is a collection of one or more folders that you can open in a single VS Code window. 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.