General
Project for automatic changing ansible vault passwords in yaml files with ansible vault strings. Use vach script wchich will be automatic installed by:
pip install vach
vach requieres some python packages:
- ansible-vault
- yaml
- argcomplete
vach don't overwrite files with vaults on default. only with -n option files with vault strings will be modified. vach uses python logging to write messages to stdout
Usage
vach [-h] [-i VID] [-g [LENGTH]] [-n] [--no-sum-file] [--tb] [-m REGEX] [-d REGEX] [-f REGEX] [-V] [PATH ...]
positional arguments:
- search in PATH for ansible vault strings and change vault passsword.
- Default: ..
- python
os.walkused for recursively file search in direct
options:
-h, --help show this help message and exit
-i VID, --vault-id VID
vault ids which password should be changed (default:
['vid'])
-g [LENGTH], --gen-passwd [LENGTH]
generate passwords for new vault ids. if no LENGTH is
provided use default length (default: None)
default password length: 20
-n, --no-dry no dry mode. files will be really written (default:
False)
--no-sum-file don't write summary json file in $HOME (default:
False)
--tb show traceback on exceptions (default: False)
-m REGEX, --match-file REGEX
handle only files that match REGEX (default: .+)
REGEX is case sensitive
-d REGEX, --ignore-dir REGEX
ignore directories that match REGEX (default:
/?\.git/?)
REGEX is case sensitive
-f REGEX, --ignore-files REGEX
ignore files that match REGEX (default: None)
REGEX is case sensitive
-V, --version show program's version number and exit
Usage examples
- show only changes in test_dir directory recursively and in files file_1, file_2. use vid_1 vault-id
vach -i vid_1 test_dir file_1 file_2
- overwrite files with vaults (no-dry mode)
vach -i vid_1 test_dir file_1 file_2 --no-dry
- handle only filenames that match some regex
vach -i vid_1 test_dir file_1 file_2 -m "\.ya?ml"
- ignore directories that match some regex
vach -i vid_1 test_dir file_1 file_2 -d "dist|build"
- ignore filenames that match some regex
vach -i vid_1 test_dir file_1 file_2 -f "\.json$"
Default values/Konfiguration
Konfig files in ini format can be used to set some default values for vach script. Konfig files can be placed in:
- ./vach.cfg
- $HOME/vach.cfg
- $HOME/.vach/vach.cfg
vach.cfg example:
[main]
passwd_length = 23
wpath = ~/vach_dir,/opt/test_dir,file_1
vault_id = vid1,vid2
match_file_regex=my?.regex
ignore_dir_regex=some_dir_regex
ignore_file_regex=ign_file_rg[Xx]
main section in vach.cfg is required
summary file
vach writes on default json summary file in the same directory. Example for a summary file (vach_summary_20250424213256.json):
{
"general": {
"all": 36,
"success": 3,
"vault": 2,
"written": 0,
"ignored": 30,
"len_bad_srcs": 0,
"bad_srcs": [],
"error": 3
},
"files": [
{
"path": "/home/firusik/vach_dir/myobject.yaml",
"succeeded": true,
"written": false,
"ignored": false,
"errors": [],
"vault_vars": []
},
{
"path": "/home/firusik/vach_dir/vach_test_file_2.yml",
"succeeded": true,
"written": false,
"ignored": false,
"errors": [],
"vault_vars": [
":oxak[1]:p",
":she:lost:control[2]",
":she:lost:begun",
":passwd"
]
},
{
"path": "/home/firusik/vach_dir/vach_error_file.yml",
"succeeded": false,
"written": false,
"ignored": false,
"errors": [
"('VaultError', VaultError('decryption of vault failed. exceptions derived from ansible: {Decryption failed (no vault secrets were found that could decrypt)}'))"
],
"vault_vars": []
},
{
"path": "/home/firusik/vach_dir/.git/description",
"succeeded": false,
"written": false,
"ignored": true,
"errors": [],
"vault_vars": []
},
...
]
}
Metadata
Release files for vach 0.25.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vach-0.25.0.tar.gz | 13.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vach-0.25.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.6 kB
Release files / vach-0.25.0.tar.gz
| Download URL | vach-0.25.0.tar.gz |
|---|---|
| Size | 13.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7e4d31666ba504a4934d6f36939dd63a219e29a044a9de0f6c1523929ef4ba0e
|
|
BLAKE2b-256 checksum How to use checksums |
ca58762ed2306d9e0d90809da9c8130c5d5f16545ddd6bf56f5ec8e20c994349
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|
Release files / vach-0.25.0-py3-none-any.whl
| Download URL | vach-0.25.0-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8923bce4ec54ecc04b45819ce77937ccf7d5c1e298ce7c923a577e38be0cab8
|
|
BLAKE2b-256 checksum How to use checksums |
f7b203d66f7327fa6c1e149fcc218796bbe1b372447622177e95763f89115b35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.2
|