Skip to content
Snippets Groups Projects
Commit bd44a8ba authored by shirenn's avatar shirenn 🌊 Committed by shirenn
Browse files

Implements new mechanism for gpg vault

The vault may now be split in multiple files under `ansible/{name}.gpg` and all
variables inside it will be loaded under `vault.name`.
parent 74eaae58
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import os ...@@ -6,6 +6,7 @@ import os
from pathlib import Path from pathlib import Path
import subprocess import subprocess
import sys import sys
import json
from ansible.module_utils.six.moves import configparser from ansible.module_utils.six.moves import configparser
from ansible.plugins.vars import BaseVarsPlugin from ansible.plugins.vars import BaseVarsPlugin
...@@ -88,11 +89,32 @@ class VarsModule(BaseVarsPlugin): ...@@ -88,11 +89,32 @@ class VarsModule(BaseVarsPlugin):
passwords = {} passwords = {}
config = configparser.ConfigParser()
config.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'pass.ini'))
password_store = Path(config.get('pass', 'password_store_dir',
fallback=os.getenv('PASSWORD_STORE_DIR', Path.home() / '.password-store')))
password_store /= config.get('pass', 'crans_password_store_submodule',
fallback=os.getenv('CRANS_PASSWORD_STORE_SUBMODULE', 'crans'))
password_store /= '.last_group.json'
with open(password_store) as file:
files = json.load(file)
files = [ file for file in files if file.startswith('ansible/') ]
for entity in entities: for entity in entities:
# Load vault passwords # Load vault passwords
if entity.get_name() == 'all': if entity.get_name() == 'all':
passwords['vault'] = {}
# Backward compatibility with old ansible_vault
passwords['vault'] = loader.load( passwords['vault'] = loader.load(
VarsModule.decrypt_password('ansible_vault', True)) VarsModule.decrypt_password('ansible_vault', True))
for file in files:
passwords['vault'][file.lstrip('ansible/')] = loader.load(
VarsModule.decrypt_password(file, True))
# Load become password # Load become password
become_password = VarsModule.become_password(entity) become_password = VarsModule.become_password(entity)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment