This library provides a simple PHP wrapper for the ansible-vault
command, allowing to encrypt and decrypt content,
and manage vaults directly within PHP.
- PHP 8.3 or later
- Ansible 2.10 or later
- Ansible Vault must be available in your system PATH
Ensure Ansible is installed and configured correctly before using this library.
You can install this library via Composer:
composer require titoshadow/ansible-vault
Include the library in your PHP code:
use Titoshadow\AnsibleVault\AnsibleVault;
...
// Create an instance of the library
$vault = new AnsibleVault('/path/to/vault-password-file');
$encryptedString = $vault->encryptString('Sensitive data');
$decryptedString = $vault->decryptString($encryptedString);
$vault->encrypt('/path/to/plain-text-file');
$vault->decrypt('/path/to/encrypted-file');
$vault->create('/path/to/new-vault-file', 'Content of the vault');
$vault->edit('/path/to/vault-file');
$vault->rekey('/path/to/vault-file', 'old-password', 'new-password');
$vault->remove('/path/to/vault-file');