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

database secrets engine config #133

Merged
merged 23 commits into from
Jun 18, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix idempotent checks az auth cfg
  • Loading branch information
drewmullen committed Jun 4, 2019
commit 22209069049bc8aab3e7cd42447c04c366789067
35 changes: 21 additions & 14 deletions ansible/modules/hashivault/hashivault_azure_auth_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def hashivault_azure_auth_config(module):
changed = False
config_file = params.get('config_file')
mount_point = params.get('mount_point')
desired_state = dict()
current_state = dict()

# do not want a trailing slash in mount_point
if mount_point[-1]:
Expand All @@ -134,36 +136,41 @@ def hashivault_azure_auth_config(module):
# if config_file is set, set sub_id, ten_id, client_id, client_secret from file
# else set from passed args
if config_file:
config = json.loads(open(params.get('config_file'), 'r').read())
tenant_id = config.get('tenant_id')
client_id = config.get('client_id')
client_secret = config.get('client_secret')
resource = config.get('resource')
desired_state = json.loads(open(params.get('config_file'), 'r').read())
if 'resource' not in desired_state:
desired_state['resource'] = params.get('resource')
if 'environment' not in desired_state:
desired_state['environment'] = params.get('environment')
else:
tenant_id = params.get('tenant_id')
client_id = params.get('client_id')
client_secret = params.get('client_secret')
resource = params.get('resource')
desired_state['tenant_id'] = params.get('tenant_id')
desired_state['client_id'] = params.get('client_id')
desired_state['client_secret'] = params.get('client_secret')
desired_state['resource'] = params.get('resource')
desired_state['environment'] = params.get('environment')

# check if engine is enabled
if (mount_point + "/") not in client.sys.list_auth_methods()['data'].keys():
return {'failed': True, 'msg': 'auth mount is not enabled', 'rc': 1}

# check if any config exists
try:
current = client.auth.azure.read_config()
current_state = client.auth.azure.read_config()
except:
changed = True

# check if current config matches desired config values, if they dont match, set changed true
if changed == False:
mismatched = {k:v for k, v in current.items() if params[k] != v}
if mismatched:
for k, v in current_state.items():
if v != desired_state[k]:
changed = True

# if changed == False:
# mismatched = {k:v for k, v in current.items() if params[k] != v}
# if mismatched:
# changed = True

# if configs dont match and checkmode is off, complete the change
if changed == True and not module.check_mode:
result = client.auth.azure.configure(tenant_id=tenant_id, client_id=client_id, client_secret=client_secret, resource=resource, mount_point=mount_point)
result = client.auth.azure.configure(mount_point=mount_point, **desired_state)

return {'changed': changed}

Expand Down