Ansible Vault for WindowsA VS Code extension to read, edit, and create Ansible Vault files — without Python, without the Built for people who work on locked-down Windows machines where installing Python packages or dev tools isn't an option. Why this existsStandard Ansible Vault plugins rely on the Features
InstallationFrom source (development)
Press Package as
|
| Command | Description |
|---|---|
Ansible Vault: Open Decrypted |
Open the active vault in an editable decrypted view |
Ansible Vault: Preview Decrypted (read-only) |
Peek at the content without entering edit mode |
Ansible Vault: Encrypt File |
Encrypt the current plain-text file as an Ansible vault |
Ansible Vault: New Encrypted File |
Create a new vault file and open it for editing |
Ansible Vault: Re-key (Change Password) |
Decrypt with the old password and re-encrypt with a new one |
Ansible Vault: Scan Workspace for Unencrypted Vaults |
Find files matching vault patterns that are not encrypted |
Ansible Vault: Install Git Pre-commit Hook |
Install a hook that blocks committing unencrypted vault files |
Ansible Vault: Clear Cached Passwords |
Wipe all in-memory cached passwords |
Keyboard shortcuts
| Action | Windows / Linux | macOS |
|---|---|---|
| Open Decrypted | Ctrl+Shift+V Ctrl+Shift+O |
Cmd+Shift+V Cmd+Shift+O |
| Encrypt File | Ctrl+Shift+V Ctrl+Shift+E |
Cmd+Shift+V Cmd+Shift+E |
Git protection
Pre-commit hook
Run Ansible Vault: Install Git Pre-commit Hook once per repository. It writes (or appends to) .git/hooks/pre-commit with a POSIX sh script that refuses any commit where a staged file:
- matches a vault-pattern name (e.g.
*.vault,secrets.yml), and - does not start with
$ANSIBLE_VAULT
The hook works on Linux, macOS, and Windows with Git Bash (the standard Git for Windows installation).
Example blocked commit:
[ansible-vault] ERROR: group_vars/all/secrets.yml matches vault pattern but is NOT encrypted!
[ansible-vault] Commit blocked. Encrypt the file(s) above before committing.
Use the VS Code command: 'Ansible Vault: Encrypt File'
or run: ansible-vault encrypt <file>
Workspace scanner
Ansible Vault: Scan Workspace for Unencrypted Vaults walks every file in the workspace that matches a vault-name pattern and lists the ones that are NOT encrypted. Results are shown in a quick-pick so you can navigate directly to any offending file.
Status bar warning
If the active file matches a vault pattern but is not encrypted, the status bar turns orange:
⚠ Vault NOT encrypted!
Clicking it runs Ansible Vault: Encrypt File.
Settings
Open Settings (Ctrl+,) and search for Ansible Vault.
| Setting | Default | Description |
|---|---|---|
ansibleVault.rememberPassword |
"session" |
"never" — ask every time; "session" — remember in memory until VS Code closes; "keychain" — persist in VS Code SecretStorage |
ansibleVault.vaultFilePatterns |
["*.vault", "vault.yml", ...] |
File-name patterns treated as vault files for warnings, scanning, and the git hook |
ansibleVault.warnOnUnencryptedVaultFiles |
true |
Show status-bar warning when a vault-pattern file is not encrypted |
ansibleVault.autoPromptOnOpen |
true |
Automatically offer to open encrypted files in decrypted view |
Ansible Vault format compatibility
The extension implements the Ansible Vault wire format exactly:
- Format 1.1 —
$ANSIBLE_VAULT;1.1;AES256(no vault ID) - Format 1.2 —
$ANSIBLE_VAULT;1.2;AES256;<vault-id>(with vault ID)
Key derivation: PBKDF2-SHA256, 10 000 iterations, 80-byte output. Encryption: AES-256-CTR. Integrity: HMAC-SHA256 of the ciphertext, verified before decryption.
Files encrypted by this extension can be decrypted with the standard ansible-vault CLI and vice versa.
Security notes
- No plaintext on disk. The
vault://virtual filesystem exists only in memory. VS Code never writes the decrypted content to a temporary file. - HMAC verification. The HMAC is always checked before decryption, so a wrong password or corrupted file is caught immediately.
- Timing-safe comparison. HMAC comparison uses
crypto.timingSafeEqualto prevent timing attacks. - Password storage. With the default
"session"strategy, passwords are held in a plain JSMapin the extension process and are lost when VS Code closes. With"keychain", they are stored in VS Code'sSecretStorage(backed by the OS credential store on Windows/macOS/Linux).
Testing
1 — Crypto unit tests (no VS Code needed)
No test framework required — just Node.js:
node test/cryptoTest.js
Expected output:
Round-trip tests
✓ encrypt + decrypt returns original plaintext
✓ round-trip with vault ID (1.2 format)
✓ each encryption produces a different ciphertext (random salt)
✓ wrong password throws
✓ corrupted data throws
isVaultEncrypted tests
✓ detects 1.1 vault
✓ detects 1.2 vault
✓ rejects plain text
✓ rejects empty string
parseHeader tests
✓ parseHeader 1.1
✓ parseHeader 1.2 with vault ID
✓ parseHeader returns null for non-vault
Results: 12 passed, 0 failed
2 — Launch the extension in VS Code
- Open the project folder in VS Code: File → Open Folder →
ansible-vault-for-windows - Press
F5(or Run → Start Debugging)
A second VS Code window opens — the Extension Development Host. All tests below are performed in that second window. Errors and console.log output appear in the first window's Debug Console tab.
The
.vscode/launch.jsonfile at the root of the project provides theF5configuration — no extra setup needed.
3 — Manual test checklist
The test/ folder contains two ready-made files:
| File | Purpose |
|---|---|
test/sample.vault |
A real encrypted vault. Password: test1234 |
test/plain_to_encrypt.yml |
A plain-text YAML file to test in-place encryption |
Open the test/ folder in the Extension Development Host window and work through these scenarios:
Open a vault decrypted
- Open
test/sample.vault - A notification appears: "Ansible Vault: 'sample.vault' is encrypted. — Open Decrypted"
- Click Open Decrypted, enter password
test1234 - A new editor tab opens showing the plain YAML content. Edit something and save (
Ctrl+S) - Verify the file on disk still starts with
$ANSIBLE_VAULT— it should, the plaintext never touched the disk
Encrypt a plain file
- Open
test/plain_to_encrypt.yml - Right-click in the editor → Ansible Vault: Encrypt File, enter a password
- The file is replaced in-place with encrypted content (first line becomes
$ANSIBLE_VAULT;1.1;AES256)
Create a new vault
Ctrl+Shift+P→ Ansible Vault: New Encrypted File- Choose a save location and set a password
- Start typing — saving (
Ctrl+S) encrypts automatically
Re-key (change password)
- Open
test/sample.vault - Right-click → Ansible Vault: Re-key (Change Password)
- Enter old password (
test1234), then a new one - Verify you can open the file again with the new password
Workspace scanner
Ctrl+Shift+P→ Ansible Vault: Scan Workspace for Unencrypted Vaults- If
plain_to_encrypt.ymlhasn't been encrypted yet, it appears in the list - Clicking an entry in the list navigates directly to the file
Git pre-commit hook
Ctrl+Shift+P→ Ansible Vault: Install Git Pre-commit Hook- Inspect
.git/hooks/pre-commit— a shell script is written there - Stage
plain_to_encrypt.ymland try to commit — the hook should block it with an error message
Status bar
| Situation | Expected status bar |
|---|---|
| Active file is an encrypted vault | 🔒 Encrypted Vault |
| Active file is open in decrypted view | 🔓 Vault (decrypted view) |
| Active file matches a vault pattern but is NOT encrypted | ⚠ Vault NOT encrypted! (orange) |
| Any other file | Status bar item hidden |
Clicking the orange warning runs Ansible Vault: Encrypt File immediately.
4 — Interop with the real ansible-vault CLI (optional)
If you have access to a Linux or macOS machine with Ansible installed, you can verify full compatibility:
# Decrypt what the extension produced
ansible-vault decrypt --vault-password-file <(echo test1234) test/sample.vault --output -
# Encrypt something with the CLI and open it with the extension
echo "secret: hello" > /tmp/mysecret.yml
ansible-vault encrypt --vault-password-file <(echo mypassword) /tmp/mysecret.yml
# Now open /tmp/mysecret.yml in the Extension Development Host
Project structure
ansible-vault-for-windows/
├── src/
│ ├── extension.js # Extension entry point, commands, decorations
│ ├── vaultCrypto.js # AES-256-CTR encrypt/decrypt (no external deps)
│ ├── vaultFileSystem.js # vault:// FileSystemProvider
│ ├── passwordManager.js # Password caching (session / keychain / never)
│ ├── statusBar.js # Status bar item
│ └── gitGuard.js # Pre-commit hook + workspace scanner
├── test/
│ └── cryptoTest.js # Self-contained crypto tests
├── package.json
└── README.md
License
MIT