/vscode-ansible

VSCode extension for ansible

Primary LanguageTypeScriptOtherNOASSERTION

Travis CI AppVeyor Marketplace Version

Visual Studio Code extension for Ansible

Table of Content

Features

  • Auto completion. Auto completion Ansible directives, modules and plugins from Ansible doc, Auto completion for variables.
  • Code snippets. Press Ctrl + Space, Ansible playbook code snippets will show up.
  • Syntax highlighting.
  • Code navigation by Symbols, press Ctrl + Shift + O.
  • Hover over module names, to show module documentation. Disable hovering over by setting ansible.hover to false.
  • Run playbook from Docker.
  • Run playbook from local Ansible installation.
  • Run playbook from Cloud Shell.
  • Run playbook remotely via ssh.

Prerequisites

platform prerequisite
Run Playbook in Cloud Shell/Remotely via ssh nodejs >= 6.0
Run Playbook in Docker Docker
Run Playbook in Local Ansible Ansible

Usage

Auto completion

Code snippets

Press Ctrl + Space in playbook yml file, you'll see Ansible modules code snippets. Then press tab to move inside snippet parameters. auto completion and code snippets

Run Ansible playbook

4 methods are supported to run Ansible playbook:

Run Playbook in Docker

  1. Make sure Docker is installed and running. For non-Windows platform, please configure Docker run without sudo.

  2. 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.
    docker share driver

  3. This step is optinal. 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.

  4. Press F1, type: ansible, choose Run Ansible Playbook in Docker. Or right click playbook yaml file, choose Run Ansible Playbook in Docker.

  5. Input playbook file full path, or use default one.

    NOTE

    • 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

  1. Make sure Ansible is installed.
  2. This step is optinal. 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 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.
  3. Press F1, type: ansible, choose Run Ansible Playbook in Local Ansible. Or right click playbook yaml file, choose Run Ansible Playbook in Local Ansible.

Run Playbook in Cloud Shell

  1. 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.
  2. Install Azure Account VSCode extension, which is used for Azure login.
  3. Press F1, type: Azure: Sign In, do Azure login.
  4. Press F1, type: ansible, choose Run Ansible Playbook in Cloud Shell. Or right click playbook yaml file, choose Run Ansible Playbook in Cloud Shell.
  5. Input playbook file full path, or use default one.
  6. Confirm awareness on Azure usage fee. Please refer to this document to learn more about Azure Cloud Shell pricing.

Run Playbook Remotely via ssh

  1. Configure your remote server in $HOME/.ssh/servers.json like below. Or follow wizard to fill in server information.
    [
         {
             "host": "your host",
             "port": 22,
             "user": "your user name",
             "password": "your ssh password",
             "key": "your private key"
         }
    ]
    

Configuration

This extension provides below configurations in settings.json.

config name description
ansible.hover Enable/Disable hover over module name functionality. Default is true.
ansible.credentialsFile Specify ansible credentials file path, used when run playbook in Docker/Local Ansible. Default is $HOME/.vscode/ansible-credentials.yml.
ansible.termininalInitCommand Specify customized terminal init command when run playbook in Docker/Local Ansible. Default is docker run command for Docker, and ansible-playbook for local ansible.

Feedback and Questions

You can submit bug or feature suggestion via issues.

License

MIT license.

Telemetry

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

Contributing

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 opencode@microsoft.com with any additional questions or comments.

Please see below documents to learn how to contribute: