VS Code Ansible Vault
This extension lets you edit Ansible Vault encrypted files as if they were plain text. It calls the ansible-vault binary to encrypt and decrypt, and the whole extension lives in one small file, so you can read all of it before you install it.
Usage
Right-click a file in the explorer or on an editor tab, then choose Open as Ansible Vault. The decrypted content opens in an editor marked with 🔒. When you save, the file is encrypted again.
- The vault-id label in the file header (
$ANSIBLE_VAULT;1.2;AES256;<label>) is kept when you save.
- If the file isn't encrypted yet, it opens as it is and gets encrypted the first time you save it.
Requirements
You need ansible-vault installed and a vault password source configured. The extension never prompts for a password, so it depends on your existing setup. It runs ansible-vault from the directory of the nearest ansible.cfg above the file, stopping at the workspace folder, so the usual settings apply:
vault_password_file or vault_identity_list in ansible.cfg, or ANSIBLE_VAULT_PASSWORD_FILE / ANSIBLE_VAULT_IDENTITY_LIST
vault_encrypt_identity to choose the vault-id for new files when several are configured
Settings
ansibleVault.executable: path to ansible-vault (default: ansible-vault on PATH).
Where plaintext goes
While encrypting, the plaintext is written to a private temp file (mode 0600, in /dev/shm where available). The extension deletes that file right after use. An open editor keeps the plaintext in memory until you close it, and the file is not decrypted again while the editor stays open.
VS Code's hot exit feature backs up unsaved changes to disk, and it does so in plaintext. Save or revert your changes before you quit, or set files.hotExit to off. VS Code's local history does not record these files.
Errors appear in the editor. For the full ansible-vault output, open the Ansible Vault output channel.