Skip to main content

changing vault passwords

Project description

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.walk used 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": []
    },
    ...
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vach-0.25.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vach-0.25.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file vach-0.25.0.tar.gz.

File metadata

  • Download URL: vach-0.25.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for vach-0.25.0.tar.gz
Algorithm Hash digest
SHA256 7e4d31666ba504a4934d6f36939dd63a219e29a044a9de0f6c1523929ef4ba0e
MD5 d5b35dc873cf0efa0fe65e7fb3b4f720
BLAKE2b-256 ca58762ed2306d9e0d90809da9c8130c5d5f16545ddd6bf56f5ec8e20c994349

See more details on using hashes here.

File details

Details for the file vach-0.25.0-py3-none-any.whl.

File metadata

  • Download URL: vach-0.25.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for vach-0.25.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8923bce4ec54ecc04b45819ce77937ccf7d5c1e298ce7c923a577e38be0cab8
MD5 a2a346f715bf3a33e139e591b9281753
BLAKE2b-256 f7b203d66f7327fa6c1e149fcc218796bbe1b372447622177e95763f89115b35

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page