Skip to content

feat: honor ANSIBLE_VAULT_PASSWORD_FILE for vault decryption#5019

Open
JohnLahr wants to merge 1 commit intoansible:mainfrom
JohnLahr:feat/vault-secrets-initialization
Open

feat: honor ANSIBLE_VAULT_PASSWORD_FILE for vault decryption#5019
JohnLahr wants to merge 1 commit intoansible:mainfrom
JohnLahr:feat/vault-secrets-initialization

Conversation

@JohnLahr
Copy link
Copy Markdown

@JohnLahr JohnLahr commented Apr 14, 2026

ansible-lint creates DataLoader instances with a hardcoded dummy vault
password, so ANSIBLE_VAULT_PASSWORD_FILE, vault_password_file in
ansible.cfg, and vault_identity_list are all silently ignored. This
causes JinjaRule and VariableNamingRule to skip fully encrypted vault
files with "Decryption failed (no vault secrets were found that could
decrypt)".

This delegates vault initialization to Ansible's own
CLI.setup_vault_secrets() (the same function that ansible-playbook
uses) and caches the result for all DataLoader instances. Interactive
prompts are disabled. When no vault configuration is found, the existing
dummy password fallback is preserved.

Fixes #2889
Fixes #2443
Related to #3718

Testing:

  • python -m pytest test/test_vault.py -v
  • python -m pytest test/test_examples.py::test_vault_full test/test_examples.py::test_vault_partial -v
  • ANSIBLE_VAULT_PASSWORD_FILE=.vault_pass ansible-lint against a project with vault-encrypted group_vars

Delegate vault secret initialization to Ansible's own
CLI.setup_vault_secrets(), which reads:

- ANSIBLE_VAULT_PASSWORD_FILE environment variable
- vault_password_file in ansible.cfg
- ANSIBLE_VAULT_IDENTITY_LIST / vault_identity_list

Previously, all DataLoader instances were initialized with a hardcoded
dummy vault password "x", causing decryption failures for fully
encrypted vault files (e.g., group_vars/*/vault.yaml). This meant
JinjaRule and VariableNamingRule silently skipped vault files.

The fix centralizes vault secret loading in _get_vault_secrets() which
caches the result and falls back to the dummy password when no vault
configuration is found. All three DataLoader creation sites
(parse_yaml_from_file, path_dwim, ansible_templar) now use the shared
_make_dataloader() factory.

Interactive prompts are disabled (ask_vault_pass=False, auto_prompt=False).

Fixes ansible#2889, ansible#2506, ansible#2443, ansible#3718
Supersedes ansible#4069

Signed-off-by: John Lahr <john@johnlahr.me>
@JohnLahr JohnLahr force-pushed the feat/vault-secrets-initialization branch from 61f7748 to d32c8e4 Compare April 14, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Ansibe-lint does not initially set vault secrets like Ansible does exception from JinjaRule and VariableNamingRule due to vault password

1 participant