-
Notifications
You must be signed in to change notification settings - Fork 157
/
hashivault_unseal.py
53 lines (46 loc) · 1.38 KB
/
hashivault_unseal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: utf-8 -*-
from ansible.module_utils.hashivault import hashivault_argspec
from ansible.module_utils.hashivault import hashivault_client
from ansible.module_utils.hashivault import hashivault_init
from ansible.module_utils.hashivault import hashiwrapper
ANSIBLE_METADATA = {'status': ['stableinterface'], 'supported_by': 'community', 'version': '1.1'}
DOCUMENTATION = '''
---
module: hashivault_unseal
version_added: "1.2.0"
short_description: Hashicorp Vault unseal module
description:
- Module to unseal Hashicorp Vault.
options:
keys:
description:
- vault key shard(s).
extends_documentation_fragment: hashivault
'''
EXAMPLES = '''
---
- hosts: localhost
tasks:
- hashivault_unseal:
keys: '{{vault_keys}}'
'''
def main():
argspec = hashivault_argspec()
argspec['keys'] = dict(required=True, type='str', no_log=True)
module = hashivault_init(argspec)
result = hashivault_unseal(module.params)
if result.get('failed'):
module.fail_json(**result)
else:
module.exit_json(**result)
@hashiwrapper
def hashivault_unseal(params):
keys = params.get('keys')
client = hashivault_client(params)
if client.sys.is_sealed():
return {'status': client.sys.submit_unseal_keys(keys.split()), 'changed': True}
else:
return {'changed': False}
if __name__ == '__main__':
main()