vaulti-ansible


Namevaulti-ansible JSON
Version 0.1.8 PyPI version JSON
download
home_pageNone
SummaryUtility for Ansible Vault inline-encrypted variables
upload_time2025-01-14 20:08:03
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords ansible ansible-vault
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Vaulti

Like `ansible-vault edit`, but for files with inline encrypted variables!

Edit, create, encrypt and decrypt ansible-vault in-line encrypted variables in yaml files.


## Usage example

https://github.com/user-attachments/assets/74480694-3333-4405-8f68-248af21c9999


## Quick start

```shell
# Install it
pip install vaulti-ansible

# Open a file for editing
vaulti file.yml

# See more options
vaulti -h
```

## Features

- Encrypt or decrypt files by adding or removing custom tags
- Change encrypted values directly
- Works for simple variables, lists, dicts, multiline variables (literals) and anchors
- Works with multiple / non-default vault-ids
- Print decrypted files to stdout
- Some Quality of Life features to let you reopen the file if simple mistakes are made

See [docs folder](docs/) for more examples and user guides


## Why this exists

The standard `ansible-vault` works fine for encrypting/decrypting/editing whole files, but there are times you don't want to encrypt entire files; for example:

If you use AWX/AAP, having vault-encrypted files is a bit difficult; you either have to:

- include the vault password in whichever container/Execution environment you are running the playbooks (therefore requiring a custom container image), or
- decrypt the file when syncing the inventory (making all your secrets plaintext for those with high enough access in AWX)

Additionally, if your control repo is getting large, with lots of `host_vars` variables, `group_vars` variables, complex playbooks and roles, and you want
to find out where certain variables are defined, you won't be able to search full vault-encrypted files easily, since all the keys are also encrypted.

So then you try inline encryption, which solves pretty much all of these problems, but using it with `ansible-vault edit <file>` is no longer possible...
you now have to do something like this instead:

```shell
## To encrypt:
ansible-vault encrypt_string # <enter>
SomePasswordOrSomething # <Ctrl-D>, NOT <enter> unless you need the newline encrypted too
# Then copy the output into your yaml file, making sure the indentation is still ok

## To edit:
# Not possible, just encrypt a new string and replace it.

## To view:
ansible -i the/relevant/inventory the-relevant-host -m debug -a "var=TheRelevantVariable"

## To decrypt:
# Not possible, just view it and copy-paste the content where needed

```

Not really easy to remember the encrypt and view steps, pretty error-prone and requires you to actually run something with ansible, putting the variable
somewhere where it will actually be read (hostvars or groupvars). It is *much* easier to just open the decrypted content and edit it directly.


## Why you should NOT use this

I am a sysadmin by trade, not really a professional programmer, and the quality of the code might reflect that. It is getting better over time, but
there may still be edge cases where strange things could happen to the file you are editing. Yaml is a pretty complex specification after all. It
isn't likely to break, and I've used it without issue for some time, but if you don't have your files in a git repo with the ability to revert files
easily, please at least initialize a git repo first and do an initial commit! If you need this utility, it's probably time for version control anyway)

## Caveats

Since it uses the fantastic (yet sparsely documented) `ruamel.yaml`, and the yaml spec is pretty extensive, this utility does
make some "non-negotiable" changes to your files that you should be aware of, that happens when we load and parse the yaml data:

- Indentation for your multiline strings will always end up with a fixed (default two) spaces relative to the variable it belongs to;
  i.e. not the 10 spaces indented or whatever the default is from the `ansible-vault encrypt_string` output. This is good for consistency, but it does mean that the indentation
  of your inline-encrypted variables will probably change the first time you use this, if you've previously used `ansible-vault encrypt_string` to generate the encrypted strings.
  If you don't change the decrypted value, it should remain the same though, except for the indent change.
- Extra whitespaces will be removed whereever it is found (for example `key:  value` -> `key: value`)

Also, there are a few "opinionated" things I've hardcoded, which are relatively easy to comment out or change in `setup_yaml()` if you wish it.

- Header (`---`) and footer (`...`) will be added automatically to the variable file if it doesn't exist.
- An indent equals two spaces
- The hyphen starting each list items is indented, not inline with the parent key
- An extra newline is added below the ansible-vault output, for readability.
- No automatic line breaks for long values.

Finally, a word on diffs. The utility revolves around decrypting and reencrypting the variables, which means that every time you open a file with it, the
encrypted string actually changes (different salt for each reencrypt). Part of the utility is therefore dedicated to looping through the re-encrypted file, comparing it with
the original decrypted data, and preferring the old encrypted string if the actual decrypted value hasn't changed. That means that any git diff produced by these changes will
usually only involve the relevant changed variables, but it is a "best effort" process. If you change the number encrypted variables in a list, the items
whose list index was changed will be re-encrypted with a new salt, since the original value cannot be found. Same goes for any variables where you change
the key name. Create the key/entry with a regular editor first if this is important to you.

## Dependencies

Won't put the dependencies in the `pyproject.toml` file for now, since with Ansible, sometimes you
want ansible-core on a specific version to keep a consistent execution environment. Any mention of
the required libraries will make pip upgrade `ansible` and `ansible-core` packages even if the
requirements don't make it necessary.

Having to use `--no-deps` for installing this tool is just asking for trouble.

Dependencies are:

```
# We're using typing classes from Python3.9, and __future__ annotations is not not available before python 3.7.
# Since ansible seems to skip 3.7, let's just say 3.8. Might work with 3.7, if you are using that for some reason.
python>=3.8 

ruamel.yaml>=0.16.6 # Won't work before this version due to TaggedScalar changes
ansible>=2.4.0.0 # Won't work for older versions due to pycrypto
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "vaulti-ansible",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "ansible, ansible-vault",
    "author": null,
    "author_email": "Ove <oveee92@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/57/b7/e0b6f29569ccd76d7ca873ff9ca9e4d7e6b8ae185276c39723a546179553/vaulti_ansible-0.1.8.tar.gz",
    "platform": null,
    "description": "# Vaulti\n\nLike `ansible-vault edit`, but for files with inline encrypted variables!\n\nEdit, create, encrypt and decrypt ansible-vault in-line encrypted variables in yaml files.\n\n\n## Usage example\n\nhttps://github.com/user-attachments/assets/74480694-3333-4405-8f68-248af21c9999\n\n\n## Quick start\n\n```shell\n# Install it\npip install vaulti-ansible\n\n# Open a file for editing\nvaulti file.yml\n\n# See more options\nvaulti -h\n```\n\n## Features\n\n- Encrypt or decrypt files by adding or removing custom tags\n- Change encrypted values directly\n- Works for simple variables, lists, dicts, multiline variables (literals) and anchors\n- Works with multiple / non-default vault-ids\n- Print decrypted files to stdout\n- Some Quality of Life features to let you reopen the file if simple mistakes are made\n\nSee [docs folder](docs/) for more examples and user guides\n\n\n## Why this exists\n\nThe standard `ansible-vault` works fine for encrypting/decrypting/editing whole files, but there are times you don't want to encrypt entire files; for example:\n\nIf you use AWX/AAP, having vault-encrypted files is a bit difficult; you either have to:\n\n- include the vault password in whichever container/Execution environment you are running the playbooks (therefore requiring a custom container image), or\n- decrypt the file when syncing the inventory (making all your secrets plaintext for those with high enough access in AWX)\n\nAdditionally, if your control repo is getting large, with lots of `host_vars` variables, `group_vars` variables, complex playbooks and roles, and you want\nto find out where certain variables are defined, you won't be able to search full vault-encrypted files easily, since all the keys are also encrypted.\n\nSo then you try inline encryption, which solves pretty much all of these problems, but using it with `ansible-vault edit <file>` is no longer possible...\nyou now have to do something like this instead:\n\n```shell\n## To encrypt:\nansible-vault encrypt_string # <enter>\nSomePasswordOrSomething # <Ctrl-D>, NOT <enter> unless you need the newline encrypted too\n# Then copy the output into your yaml file, making sure the indentation is still ok\n\n## To edit:\n# Not possible, just encrypt a new string and replace it.\n\n## To view:\nansible -i the/relevant/inventory the-relevant-host -m debug -a \"var=TheRelevantVariable\"\n\n## To decrypt:\n# Not possible, just view it and copy-paste the content where needed\n\n```\n\nNot really easy to remember the encrypt and view steps, pretty error-prone and requires you to actually run something with ansible, putting the variable\nsomewhere where it will actually be read (hostvars or groupvars). It is *much* easier to just open the decrypted content and edit it directly.\n\n\n## Why you should NOT use this\n\nI am a sysadmin by trade, not really a professional programmer, and the quality of the code might reflect that. It is getting better over time, but\nthere may still be edge cases where strange things could happen to the file you are editing. Yaml is a pretty complex specification after all. It\nisn't likely to break, and I've used it without issue for some time, but if you don't have your files in a git repo with the ability to revert files\neasily, please at least initialize a git repo first and do an initial commit! If you need this utility, it's probably time for version control anyway)\n\n## Caveats\n\nSince it uses the fantastic (yet sparsely documented) `ruamel.yaml`, and the yaml spec is pretty extensive, this utility does\nmake some \"non-negotiable\" changes to your files that you should be aware of, that happens when we load and parse the yaml data:\n\n- Indentation for your multiline strings will always end up with a fixed (default two) spaces relative to the variable it belongs to;\n  i.e. not the 10 spaces indented or whatever the default is from the `ansible-vault encrypt_string` output. This is good for consistency, but it does mean that the indentation\n  of your inline-encrypted variables will probably change the first time you use this, if you've previously used `ansible-vault encrypt_string` to generate the encrypted strings.\n  If you don't change the decrypted value, it should remain the same though, except for the indent change.\n- Extra whitespaces will be removed whereever it is found (for example `key:  value` -> `key: value`)\n\nAlso, there are a few \"opinionated\" things I've hardcoded, which are relatively easy to comment out or change in `setup_yaml()` if you wish it.\n\n- Header (`---`) and footer (`...`) will be added automatically to the variable file if it doesn't exist.\n- An indent equals two spaces\n- The hyphen starting each list items is indented, not inline with the parent key\n- An extra newline is added below the ansible-vault output, for readability.\n- No automatic line breaks for long values.\n\nFinally, a word on diffs. The utility revolves around decrypting and reencrypting the variables, which means that every time you open a file with it, the\nencrypted string actually changes (different salt for each reencrypt). Part of the utility is therefore dedicated to looping through the re-encrypted file, comparing it with\nthe original decrypted data, and preferring the old encrypted string if the actual decrypted value hasn't changed. That means that any git diff produced by these changes will\nusually only involve the relevant changed variables, but it is a \"best effort\" process. If you change the number encrypted variables in a list, the items\nwhose list index was changed will be re-encrypted with a new salt, since the original value cannot be found. Same goes for any variables where you change\nthe key name. Create the key/entry with a regular editor first if this is important to you.\n\n## Dependencies\n\nWon't put the dependencies in the `pyproject.toml` file for now, since with Ansible, sometimes you\nwant ansible-core on a specific version to keep a consistent execution environment. Any mention of\nthe required libraries will make pip upgrade `ansible` and `ansible-core` packages even if the\nrequirements don't make it necessary.\n\nHaving to use `--no-deps` for installing this tool is just asking for trouble.\n\nDependencies are:\n\n```\n# We're using typing classes from Python3.9, and __future__ annotations is not not available before python 3.7.\n# Since ansible seems to skip 3.7, let's just say 3.8. Might work with 3.7, if you are using that for some reason.\npython>=3.8 \n\nruamel.yaml>=0.16.6 # Won't work before this version due to TaggedScalar changes\nansible>=2.4.0.0 # Won't work for older versions due to pycrypto\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Utility for Ansible Vault inline-encrypted variables",
    "version": "0.1.8",
    "project_urls": {
        "Homepage": "https://github.com/oveee92/vaulti",
        "Issues": "https://github.com/oveee92/vaulti/issues",
        "Repository": "https://github.com/oveee92/vaulti"
    },
    "split_keywords": [
        "ansible",
        " ansible-vault"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a93e567bf13f98f51481a127cda229843fbfa264afd037b2c9041e93ee6c226d",
                "md5": "6cf0277c3d450e89492f9342cee8dc2e",
                "sha256": "021e287e21d2ac55f773dc8b1dbd3709738ef950acab836512c4a1427b8b3fe4"
            },
            "downloads": -1,
            "filename": "vaulti_ansible-0.1.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6cf0277c3d450e89492f9342cee8dc2e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 15092,
            "upload_time": "2025-01-14T20:08:00",
            "upload_time_iso_8601": "2025-01-14T20:08:00.941496Z",
            "url": "https://files.pythonhosted.org/packages/a9/3e/567bf13f98f51481a127cda229843fbfa264afd037b2c9041e93ee6c226d/vaulti_ansible-0.1.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "57b7e0b6f29569ccd76d7ca873ff9ca9e4d7e6b8ae185276c39723a546179553",
                "md5": "750a9f1ee708811889ed08e628e0b6f1",
                "sha256": "bf5cdec88ced66b6d1630e26055a637a561dfeaf47e82c4854313edd86bf79e4"
            },
            "downloads": -1,
            "filename": "vaulti_ansible-0.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "750a9f1ee708811889ed08e628e0b6f1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18898,
            "upload_time": "2025-01-14T20:08:03",
            "upload_time_iso_8601": "2025-01-14T20:08:03.504975Z",
            "url": "https://files.pythonhosted.org/packages/57/b7/e0b6f29569ccd76d7ca873ff9ca9e4d7e6b8ae185276c39723a546179553/vaulti_ansible-0.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-14 20:08:03",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "oveee92",
    "github_project": "vaulti",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "vaulti-ansible"
}
        
Elapsed time: 0.66354s