Visual Studio Code extension for Ansible
The VSCode ansible extension is designed to increase developer productivity authoring, testing and using Ansible with Azure. The extension provides cool features around playbook authoring and execution. It supports running playbook from various places e.g. Docker, local installation, remote machines via ssh and Cloud Shell.
Table of Content
- Auto completion. Auto completion Ansible directives, modules and plugins from Ansible doc, Auto completion for variables. Disable auto completion by setting
- Code snippets. Press
Ctrl + Space, Ansible playbook code snippets will show up.
- Syntax highlighting. Enable syntax highlighting by setting
- Yaml validation. Yaml validation by leverage Yaml language server.
- Code navigation by Symbols, press
Ctrl + Shift + O.
- Hover over module names, to show module documentation. Disable hovering over by setting
- Run playbook from Docker.
- Run playbook from local Ansible installation.
- Run playbook from Cloud Shell.
- Run playbook remotely via ssh.
- Auto File Copy to remote host on saving.
This extension provides below configurations in settings.json.
|Enable/Disable ansible autocompletion(including code snippets) functionality. To enable ansible autocompletion only in specific yaml files, set
ansible.autocompletion = false, then add
# ansible-configured header in first line of yaml file.
|Enable/Disable hover over module name functionality.
|Enable/Disable SSH terminal reusing.
|Specify ansible credentials file path, used when run playbook in Docker/Local Ansible.
docker run command for Docker.
|Specify customized terminal init command when run playbook in Docker.
|Docker image name when running playbook in Docker.
|Customize run playbook options. eg.
-i xxxx -vvv.
|File copying configuration when running playbook remotely via SSH. It's array of configuration. Please see detail at here
|Run Playbook in Cloud Shell/Remotely via ssh
||nodejs >= 6.0
|Run Playbook in Docker
|Run Playbook in Local Ansible
Associate your Yaml files with
ansible language in VSCode
Code snippets will be in auto-completed list with suffix
tab to move inside snippet parameters.
Enable syntax highlighting by adding
settings.json, to associate your paths with
ansible language, please see sample.
Run Ansible playbook
Run Playbook in Docker
Make sure Docker is installed and running. For non-Windows platform, please configure Docker run without sudo.
Default docker image is microsoft/ansible:latest, which is latest Ansible version. Customizing your own docker image by configuration item
ansible.dockerImage, customizing docker init command by configuration
docker run -i -t microsoft/ansible:ansible2.5.5 /bin/bash. Detail please see configuration.
For Windows user, please share your Windows driver where vscode workspace sits on with docker. This is because the extension will map your workspace containing playbook with docker.
This step is optional. If you want to run cloud provider specific Ansible modules, you need set cloud credentials in credential yaml file, default path is
$HOME/.vscode/ansible-credentials.yml, or change credential file path by settings item
ansible.credentialsFile. Credential file template is at here.
Run Ansible Playbook in Docker. Or right click playbook yaml file, choose
Run Ansible Playbook in Docker.
- Docker on Windows is not as stable as on other platforms, please try to restart Docker in case of any issue.
- Downloading Docker image first time usage may be time consuming in case of slow network connection.
Run Playbook in Local Ansible
- Make sure Ansible is installed.
- This step is optional. If you want to run cloud provider specific Ansible modules, please setup cloud credentials by following Ansible instruction. Or you can set cloud credentials in credential file, default path is
$HOME/.vscode/ansible-credentials.yml, change credential file path by settings item
ansible.credentialsFile. Credential file template is at here.
Run Ansible Playbook in Local Ansible. Or right click playbook yaml file, choose
Run Ansible Playbook in Local Ansible.
Run Playbook in Cloud Shell
- Important Please setup Cloud Shell for first time usage in Azure Portal by following this instruction. After setup, input cmd
az account show to learn your current subscription setting.
- Install Azure Account VSCode extension, which is used for Azure login.
Azure: Sign In, do Azure login.
Run Ansible Playbook in Cloud Shell. Or right click playbook yaml file, choose
Run Ansible Playbook in Cloud Shell.
- Confirm awareness on Azure usage fee. Please refer to this document to learn more about Azure Cloud Shell pricing.
- Known issue due to adal issue, introduced in azure account extension, user might see
Entry not found error when connect to cloud shell. Please retry open cloud shell.
Run Playbook Remotely via ssh
Run Ansible Playbook Remotely via ssh, follow wizard to pick up/add remote host. Or configure your remote server in
$HOME/.ssh/servers.json like below.
"host": "your host",
"user": "your user name",
"password": "your ssh password",
"key": "your private key",
"passphrase": "your passphrase"
Files copy to remote on saving
- Configure file copying to remote host on saving as below in
sourcePath will be copied to remote
targetPath when configuration added/updated.
copyOnSave will copy local saved files to remote host.
"sourcePath": "local file/folder to copy from, eg. e:\\testfolder\\ansibleplaybooks",
"targetPath": "remote file/folder to copy to, eg. /home/user/ansibleplaybooks",
"copyOnSave": true // When true, files saved inside VSCode will be copied automatically to remote host.
There's notification message at right side of status bar.
Samples for azure_rm_resource (Preview)
This command provides sample code snippets for azure_rm_resource module, those samples are from Azure Rest API spec.
To use, press F1 and then select Ansible: Samples for azure_rm_resource (PREVIEW) command.
You will be first asked for API group, then required operation. After selecting operation a pickup list will be displayed where you can select particular API version and sample. Extension will create appropriate playbook based on azure_rm_resource or azure_rm_resource_facts module.
Note that all the samples generated by the extension are based on REST API samples from this repository:
Please also refer to Azure REST API reference here:
In case of any bugs encountered in samples please fill an issue here:
Note 1: This feature requires Ansible >= 2.7.
Note 2: When using for the first time it may take a few minutes to retrieve REST API specifications.
Feedback and Questions
You can submit bug or feature suggestion via issues.
This extension collects telemetry data to help improve our products. Please read Microsoft privacy statement to learn more. If you opt out to send telemetry data to Microsoft, please set below configuration in settings.json:
telemetry.enableTelemetry = false
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
This project has adopted the Microsoft Open Source Code of Conduct.
For more information see the Code of Conduct FAQ or
contact firstname.lastname@example.org with any additional questions or comments.
Please see below documents to learn how to contribute:
Release Notes and Thank you
Please see our releases to see detail in each release, and
Thank you. Or check CHANGELOG.