Metadata-Version: 2.4
Name: pilfer
Version: 3.3.0
Summary: CLI to bulk decrypt/re-encrypt Ansible vault files in a project tree for editing.
Author-email: Tom Paine <github@aioue.net>
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://aioue.net/2026/08/07/pilfer-bulk-ansible-vault-edit/
Project-URL: Documentation, https://aioue.net/2026/08/07/pilfer-bulk-ansible-vault-edit/
Project-URL: Repository, https://github.com/aioue/pilfer
Project-URL: Issues, https://github.com/aioue/pilfer/issues
Project-URL: Changelog, https://github.com/aioue/pilfer/releases
Keywords: ansible,ansible-vault,vault,secrets,secrets-management,encryption,decrypt,encrypt,rekey,devops,automation,infrastructure,cli,yaml
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: System :: Systems Administration
Classifier: Topic :: Utilities
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: PILFER_LICENSE.txt
Requires-Dist: ansible-core>=2.21
Requires-Dist: shtab>=1.7
Provides-Extra: keyring
Requires-Dist: keyring>=25; extra == "keyring"
Dynamic: license-file

[![CI](https://github.com/aioue/pilfer/actions/workflows/ci.yml/badge.svg)](https://github.com/aioue/pilfer/actions/workflows/ci.yml)
[![Test Suite](https://github.com/aioue/pilfer/actions/workflows/test.yml/badge.svg)](https://github.com/aioue/pilfer/actions/workflows/test.yml)
[![CodeQL](https://github.com/aioue/pilfer/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/aioue/pilfer/actions/workflows/github-code-scanning/codeql)
[![Dependabot enabled](https://img.shields.io/badge/dependabot-enabled-025E8C?logo=dependabot&logoColor=white)](https://github.com/aioue/pilfer/network/updates)
[![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

# pilfer

**Decrypt *all* ansible vault files in a project in-place recursively for viewing/editing, then re-encrypt them all at once when you're done.**

Optionally decrypt/re-encrypt all [inline `!vault` values](https://docs.ansible.com/projects/ansible/latest/vault_guide/vault_encrypting_content.html) in-place, or re-key an entire tree after a password exposure.

## Output

Example session:

![Example pilfer open and close session](https://raw.githubusercontent.com/aioue/pilfer/master/docs/pilfer-session.svg)

<details>
<summary>Plain-text transcript</summary>

```text
$ pilfer open --include-encrypted-vars --quiet
🔓 Searching for and decrypting vault files...
ℹ️  Found 4 vault target(s) (3 whole-file, 1 with inline values)
✅ All vault files decrypted. Edit as needed, then run 'pilfer close' to re-encrypt.
$ pilfer close
🔒 Re-encrypting vault files...
ℹ️  Re-encrypting modified file: inventory/group_vars/all/secrets.yml
ℹ️  Re-encrypting modified inline value(s) in: inventory/group_vars/all/all.yml (1 changed)
✅ Vault files re-encrypted. 2 modified files have been updated.
```

</details>

## Quick start

Requires **Python 3.12+** and **ansible-core 2.21+**. `pip install pilfer` installs ansible-core.

```bash
pipx install pilfer
cd your-ansible-project
pilfer open
# edit or search plaintext
pilfer close
```

Unchanged files are restored to their original ciphertext automatically.

Add to `ansible.cfg` so you do not need `-p FILE` on every run:

```ini
[defaults]
vault_password_file = ~/.ansible-vault/.vault-file
```

## Features

- **Fail-safe and battle tested:** power outages and fat-fingers won't lose data
- **Recursive:** finds whole-file vaults anywhere under the current directory
- **Supports inline `!vault` values:** decrypted in place inside normal YAML
- **Clean diffs:** only modified files are re-encrypted
- **Re-keying:** re-encrypts all your vaults with a new password after a leak
- **Native Ansible:** uses Ansible's own code for operations - no surprises
- **Better than native:** `pilfer set` inserts a key's secret into a vault file in one command
- **Keyring client:** keep the vault password in the macOS Keychain or Linux Secret Service
- **Extensible:** works with any client script, e.g. `age` with a YubiKey or Secure Enclave plugin

## Commands

| Command | Purpose | Example |
|---------|---------|---------|
| `open` | Decrypt the vault files in this tree | `pilfer open` |
| `close` | Re-encrypt what `open` decrypted | `pilfer close` |
| `status` | Show whether a session is open and which files hold plaintext | `pilfer status` |
| `find-keys` | List which vault files hold a key; never prints values | `pilfer find-keys '*token*'` |
| `get` | Print one value, for piping into a command | `pilfer get db_password \| psql ...` |
| `set` | Add or replace one key in a closed vault file | `pilfer set secrets.yml db_password` |
| `update` | Replace an existing key in whichever file holds it | `pilfer update db_password` |
| `rekey` | Change the vault password across the tree | `pilfer rekey --dry-run --new-vault-id prompt` |
| `completion` | Print a bash or zsh completion script | `pilfer completion zsh > ~/.zfunc/_pilfer` |
| `agent-guide` | Print a `SKILL.md` for AI coding agents | `pilfer agent-guide` |

Run `pilfer COMMAND --help` for options, examples and exit statuses. [docs/commands.md](https://github.com/aioue/pilfer/blob/master/docs/commands.md) covers output formats, JSON shapes and the reasoning behind the commands.

## Inline values

Whole-file vaults open by default. Inline `!vault` values are opt-in:

```bash
pilfer open --include-encrypted-vars
```

Each value becomes one quoted line followed by a `# pilfer:vault:N` marker, for example `db_password: "the-secret"  # pilfer:vault:0`. Do not remove the marker: `close` uses it to find and re-encrypt the value. Do not commit while markers are present, or the plaintext and the session metadata land in git. `close` needs no flag and re-encrypts everything the session opened.

See [docs/inline.md](https://github.com/aioue/pilfer/blob/master/docs/inline.md) for the supported forms, what `close` checks and the refusal messages.

## Vault passwords

Pilfer loads passwords with Ansible's own code, in the order `ansible-vault` uses: `vault_identity_list`, `--vault-id`, `-p`, `vault_password_file`, then the `-J` prompt. With no source named, it falls back to a few plain password files such as `~/.ansible-vault/.vault-file`. `pilfer-vault-keyring-client` is a client script that reads the password from the macOS Keychain or Linux Secret Service.

**Security:** because pilfer loads passwords as `ansible-vault` does, a `vault_password_file` script named by the project's `ansible.cfg` runs whenever a command needs a password, even with `-p`. In a repo you did not write, read `ansible.cfg` first or point `ANSIBLE_CONFIG` at a file you trust.

See [docs/passwords.md](https://github.com/aioue/pilfer/blob/master/docs/passwords.md) for the full order, fallback paths and keyring setup.

## Rotating the vault password

`pilfer close` never changes a password. `pilfer rekey` rotates every vault in the current directory and below:

```bash
pilfer rekey --old-vault-password-file OLD --new-vault-password-file NEW --dry-run
pilfer rekey --old-vault-password-file OLD --new-vault-password-file NEW
pilfer rekey --old-vault-password-file OLD --new-vault-password-file NEW --rotate-password-file
```

The first checks that everything decrypts and prints the plan. The second asks you to type `REKEY`. The third also keeps the old password in `<file>_old` and installs the new one at the old path. After a failure, run the same command again to resume. See [docs/rekey.md](https://github.com/aioue/pilfer/blob/master/docs/rekey.md).

## Safety

Pilfer **fails closed**: if it cannot prove a secret is safely re-encrypted or intentionally removed, it keeps the session and the `.vault/` backups and exits non-zero. It does not invent fixes for ambiguous edits.

What to know:

- Never commit while a session is open.
- `close` is progressive: files that succeed are encrypted and dropped from the session, and failures stay plaintext until you fix them. Check its exit status.
- A session belongs to the directory where `open` ran. `pilfer status` reports sessions above and below the current directory.
- Deleting or emptying an opened file needs an explicit choice (`pilfer close --confirm-delete`, or put the content back).

More in [docs/safety.md](https://github.com/aioue/pilfer/blob/master/docs/safety.md).

### Gitignore

```gitignore
vaultedFileList.json
.vault/
**/*.pilfer-open
# Lock file that exists while pilfer works on a vault. Left behind only if pilfer is killed.
**/*.pilfer-lock
# Temp a killed pilfer can leave beside a file. The next open, close or rekey deletes it.
**/.pilfer-rekey-*
# --rotate-password-file leaves the old password here. Add `<your password file>_old`
# if your password file is inside the project.
.vault_password_old
vault_password_file_old
# `pilfer open` puts plaintext at the real path, so an editor's swap, backup and
# undo files beside it hold secrets and outlive `pilfer close`.
*~
.*.sw?
\#*\#
.*.un~
```

These patterns cover Vim and Emacs defaults. Check where your own editor writes backups and undo history; a central undo directory is outside the project and is not covered.

### Pre-commit hook

A hook that compares content refuses a commit that turns a vault file into plaintext, and one that carries `# pilfer:vault:` markers. See [docs/safety.md](https://github.com/aioue/pilfer/blob/master/docs/safety.md#pre-commit-hook) for the script.

### Recovery

If `close` refuses, fix what it reports and run `pilfer close` again. If the session list or the `.vault/` backups are lost, [docs/safety.md](https://github.com/aioue/pilfer/blob/master/docs/safety.md#recovery) has the steps for each case.

## For AI agents

`pilfer agent-guide` prints a `SKILL.md` that tells a coding agent to find and change secrets with `find-keys`, `update` and `set` without printing values. Install it where your agent reads skills:

```bash
mkdir -p ~/.agents/skills/pilfer && pilfer agent-guide > ~/.agents/skills/pilfer/SKILL.md
```

Claude Code reads `~/.claude/skills/pilfer/SKILL.md`. Run it again after upgrading pilfer. See [docs/commands.md](https://github.com/aioue/pilfer/blob/master/docs/commands.md#for-ai-agents) for the rest.

## License

GPLv3+. See [`PILFER_LICENSE.txt`](https://github.com/aioue/pilfer/blob/master/PILFER_LICENSE.txt).

## Credits

Borrows heavily from the excellent, but no longer supported [Ansible Toolkit](https://github.com/dellis23/ansible-toolkit).

Maintainers: development setup, releases, and CI details in [`.github/workflows/README.md`](https://github.com/aioue/pilfer/blob/master/.github/workflows/README.md).
