Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ansible_vault_keys-0.2.3.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ansible_vault_keys-0.2.3-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file ansible_vault_keys-0.2.3.tar.gz.

File metadata

  • Download URL: ansible_vault_keys-0.2.3.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for ansible_vault_keys-0.2.3.tar.gz
Algorithm Hash digest
SHA256 fb3707cf611a2d08e378737faf2eedaf45166f1fd0b05ec70782b2702713690d
MD5 5103548419dba998b65d67556cf4c8d6
BLAKE2b-256 e20fabd76c76bdef4d20c0b5c1d3258b9cf35dbe8e7dce0495c46530bcefbd06

See more details on using hashes here.

File details

Details for the file ansible_vault_keys-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_vault_keys-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c480496896a2d62dcb2ddf1ffba2da3d1d318e527efe59176fd0cfceb7b2998c
MD5 a0b1dd433ebcdba23c817c1c71070bc8
BLAKE2b-256 b315f985a1b117b603e66ba31328586f009e571bd598125a871106282ceeb420

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page