Skip to main content

ansible-vault-keys

Coverage Tests License Python Repo Size Last Commit PyPI Encryption Style YAML Fidelity

Selective encryption of YAML keys using Ansible Vault — with full round-trip support.

✨ Why?

Ansible Vault is great for securing secrets, but encrypting entire files makes them opaque and hard to document.

This tool lets you encrypt only the sensitive keys in your YAML files, preserving:

  • ✅ Comments
  • ✅ Key order
  • ✅ Formatting
  • ✅ Readability

No more guessing what's inside a vault-encrypted blob. Just mark the keys you want to encrypt, and keep the rest visible.

🧙‍♂️ Philosophy

This tool is itended to be a companion to ansible-vault, not a replacement. It’s built for clarity, maintainability, and expressive workflows — especially when documenting or collaborating on infrastructure.

Think of it as a scribe that encrypts only what must be hidden, while preserving the story around it. In keeping with the design goals - Your YAML remains readable, annotated, and collaborative — even when secrets are tucked away.

🚀 Quickstart

Encrypt selected keys in a YAML file:

ansible-vault-keys encrypt somevars.yaml

Decrypt them later:

ansible-vault-keys decrypt somevars.yaml

View decrypted values without modifying the file

ansible-vault-keys view somevars.yaml

🧾 Before

# somevars.yaml
plain: value
# this one is sensitive v
password: somesensitivevalue
user: bob
# so is this one v
apikey: nue6756be8cs83jn2l4
encrypted_keys: [password, apikey]

🔐 After Encryption

# somevars.yaml
plain: value
# this one is sensitive v
password: !vault |  # 🔐 Encrypted keys are marked with !vault
  $ANSIBLE_VAULT;1.1;AES256
  ...
user: bob
# so is this one v
apikey: !vault |   # 🔐 Encrypted keys are marked with !vault
  $ANSIBLE_VAULT;1.1;AES256
  ...
encrypted_keys: [password, apikey]

🔐 Encrypted keys are marked with !vault This comment is for illustration only — it’s not included in the actual output.

Commands Table:

Command Description
encrypt Encrypts keys listed in encrypted_keys or specified with --keys
decrypt Decrypts all vault-encrypted values
view Displays decrypted values without modifying the file

Flags Table:

Flag Description
--dry-run Show changes without writing to file
--vault-password-file Path to vault password file (default: vault.password)
--keys Merge with encrypted_keys list from YAML

Clarify the --keys Behavior

⚠️ Note: --keys are merged with any existing encrypted_keys list during encryption.

Usage:

usage: ansible-vault-keys [-h] [--output [OUTPUT]] [--vault-password-file VAULT_PASSWORD_FILE] [--keys KEYS [KEYS ...]] [--dry-run] {encrypt,decrypt,view} input

Selectively encrypt sensitive variables

positional arguments:
  {encrypt,decrypt,view}
                        Command to execute
  input                 Path to input YAML file

options:
  -h, --help            show this help message and exit
  --output [OUTPUT]     Path to output YAML file (optional), defaults to input file, will clobber without warning
  --vault-password-file VAULT_PASSWORD_FILE
                        Path to vault password file
  --keys KEYS [KEYS ...]
                        Keys to encrypt
  --dry-run             Show changes without writing to file

📦 Install

Install locally for CLI use:

pip install .

Or build a wheel:

python -m build

After installation, the ansible-vault-keys command will be available in your shell.

📝 License

MIT

Metadata

Release files for ansible-vault-keys 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansible-vault-keys 0.2.3
File Size Uploaded
ansible_vault_keys-0.2.3.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ansible-vault-keys 0.2.3
File Interpreter ABI Platform
ansible_vault_keys-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / ansible_vault_keys-0.2.3.tar.gz

Download URL ansible_vault_keys-0.2.3.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fb3707cf611a2d08e378737faf2eedaf45166f1fd0b05ec70782b2702713690d
BLAKE2b-256 checksum
How to use checksums
e20fabd76c76bdef4d20c0b5c1d3258b9cf35dbe8e7dce0495c46530bcefbd06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / ansible_vault_keys-0.2.3-py3-none-any.whl

Download URL ansible_vault_keys-0.2.3-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c480496896a2d62dcb2ddf1ffba2da3d1d318e527efe59176fd0cfceb7b2998c
BLAKE2b-256 checksum
How to use checksums
b315f985a1b117b603e66ba31328586f009e571bd598125a871106282ceeb420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page