Created
November 29, 2018 16:09
-
-
Save veryhappythings/92dbf3e4c9c8a6250b25884b2009f49e to your computer and use it in GitHub Desktop.
Ansible vault decrypter - supports partially encrypted files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import getpass | |
import yaml | |
from ansible.parsing.utils.yaml import from_yaml | |
from ansible.parsing.vault import VaultSecret | |
def main(input_filename, secret, output_filename): | |
result = from_yaml( | |
open(input_filename), | |
vault_secrets=[('', VaultSecret(secret))], | |
) | |
stripped = {} | |
for k, v in result.items(): | |
stripped[str(k)] = str(v) | |
with open(output_filename, 'w') as f: | |
f.write(yaml.dump(stripped, default_flow_style=False)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Vault decrypter') | |
parser.add_argument('input_filename') | |
parser.add_argument('output_filename') | |
args = parser.parse_args() | |
secret = getpass.getpass('Please input secret: ') | |
main(args.input_filename, secret, args.output_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment