Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating to allow for path in pillar variable #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions pillar/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,15 @@ def couple(location, conn):
if coupled_data or not CONF["unset_if_missing"]:
return coupled_data


def merge(dict_a, dict_b):
""" Merge dictionary needed for managing vault.conf
"""
if dict_a.keys()[0] == dict_b.keys()[0]:
temp_val = dict_a.keys()[0]
dict_a[temp_val] = merge(dict_a[temp_val], dict_b[temp_val])
else:
dict_a.update(dict_b)
return dict_a

def ext_pillar(minion_id, pillar, *args, **kwargs):
""" Main handler. Compile pillar data for the specified minion ID
Expand Down Expand Up @@ -237,7 +245,18 @@ def ext_pillar(minion_id, pillar, *args, **kwargs):
for variable, location in secrets.items():
return_data = couple(location,conn)
if return_data:
vault_pillar[variable] = return_data


if '/' in variable:
leading_str = ''
trailing_str = ''
for i in variable.split('/')[1:]:
leading_str=leading_str+"{\"" + i + "\" : "
trailing_str = trailing_str + "}"
comp_str = eval(leading_str + str(return_data['data']) + trailing_str)
variable = variable.split('/', 1)[0]
if variable in vault_pillar:
vault_pillar[variable]=merge(vault_pillar[variable],comp_str)
else:
vault_pillar[variable] = comp_str
else:
vault_pillar[variable] = return_data['data']
return vault_pillar