A Python utility to extract and decrypt Ansible vault-encrypted values from YAML files. This tool provides a simple way to access vault-protected variables without needing to write a full Ansible playbook.
- Extract and decrypt Ansible vault-encrypted values from YAML files
- Multiple output formats: YAML, environment variables, or debug output
- Clean, filtered output (removes Ansible internal variables)
- Simple command-line interface
- Cross-platform compatibility
- Python 3.6 or higher
- Ansible installed and available in your PATH
- Access to the vault password file
- Clone this repository:
git clone https://github.com/rut31337/ansible-extractor.git
cd ansible-extractor- Make the script executable (optional):
chmod +x extract_vault_values.pyExtract vault-encrypted values and display as YAML:
python extract_vault_values.py --yaml-file secrets.yml --vault-password-file vault_password.txtYAML format (default):
python extract_vault_values.py --yaml-file secrets.yml --vault-password-file vault_password.txtEnvironment variables format:
python extract_vault_values.py --yaml-file secrets.yml --vault-password-file vault_password.txt --envDebug output (raw Ansible output):
python extract_vault_values.py --yaml-file secrets.yml --vault-password-file vault_password.txt --debug--yaml-file: Path to the YAML file with vault-encrypted values (required)--vault-password-file: Path to the vault password file (required)--debug: Show verbose ansible debug output--env: Output as exported environment variables with uppercase keys
python extract_vault_values.py --yaml-file config/secrets.yml --vault-password-file .vault_passOutput:
database_url: "postgresql://user:pass@localhost/db"
api_key: "sk-1234567890abcdef"
python extract_vault_values.py --yaml-file config/secrets.yml --vault-password-file .vault_pass --envOutput:
export DATABASE_URL="postgresql://user:pass@localhost/db"
export API_KEY="sk-1234567890abcdef"
source <(python extract_vault_values.py --yaml-file config/secrets.yml --vault-password-file .vault_pass --env)The tool works by:
- Creating a temporary Ansible inventory file
- Running
ansible debugwith the provided YAML file and vault password - Parsing the Ansible output to extract variables
- Filtering out Ansible internal variables
- Outputting the results in the requested format
The tool includes comprehensive error handling for:
- Missing input files
- Invalid vault passwords
- Ansible command failures
- JSON parsing errors
- General exceptions
- The vault password file should be kept secure and not committed to version control
- Temporary files are automatically cleaned up after use
- The tool only extracts non-Ansible internal variables
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.