Centralising Common logic
@@ -251,3 +251,45 @@ class AppRoleClient(object):
resp = client.auth_approle(role_id, secret_id=secret_id, mount_point=login_mount_point)
client.token = str(resp['auth']['client_token'])
return attr
+
+
+def check_secrets_engines(module, client):
+ """Checks if secrets engine is mounted
+
+ :param module: Ansible module. Must contain mount_point in parameters.
+ :param mounted: HVAC client
+ :return: change status, error
+ :rtype: (bool, dict)
+ """
+ changed = False
+ err = None
+ try:
+ if (module.params.get('mount_point') + "/") not in client.sys.list_mounted_secrets_engines()['data'].keys():
+ err = {'failed': True, 'msg': 'secret engine is not enabled', 'rc': 1}
+ except:
+ if module.check_mode:
+ changed = True
+ else:
+ err = {'failed': True, 'msg': 'secret engine is not enabled or namespace does not exist', 'rc': 1}
+ return changed, err
+
+def check_auth_methods(module, client):
+ """Checks if auth engine is mounted
+
+ :param module: Ansible module. Must contain mount_point in parameters.
+ :param mounted: HVAC client
+ :return: change status, error
+ :rtype: (bool, dict)
+ """
+ changed = False
+ err = None
+ try:
+ if (module.params.get('mount_point') + "/") not in client.sys.list_auth_methods()['data'].keys():
+ err = {'failed': True, 'msg': 'auth method is not enabled', 'rc': 1}
+ except:
+ if module.check_mode:
+ changed = True
+ else:
+ err = {'failed': True, 'msg': 'auth mount is not enabled or namespace does not exist', 'rc': 1}
+
+ return changed, err
