forked from TerryHowe/ansible-modules-hashivault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashivault_write_from_file.py
executable file
·65 lines (47 loc) · 2.06 KB
/
hashivault_write_from_file.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
54
55
56
57
58
59
60
61
62
63
64
65
########################################################################
#
# Developed for AT&T by Nicholas Gibson, August 2017
#
# Action plugin for hashivault_write_from_file module.
#
# Reads file from remote host using slurp module. (base64 encoded)
# Stores file/secret to Vault using hashivault_read module on localhost.
#
########################################################################
from ansible.plugins.action import ActionBase
from ansible.utils.vars import merge_hash
class ActionModule(ActionBase):
def run(self, tmp=None, task_vars=None):
if task_vars is None:
task_vars = dict()
results = super(ActionModule, self).run(tmp, task_vars)
args = self._task.args.copy()
key = args.pop('key', None)
path = args.pop('path', None)
new_module_args = {
'src': path
}
self._update_module_args('slurp', new_module_args, task_vars)
results = merge_hash(
results,
# executes slurp module on remote host
self._execute_module(module_name='slurp', tmp=tmp, task_vars=task_vars, module_args=new_module_args)
)
if 'failed' in results and results['failed'] is True:
return results
# already base64 encoded from slurp
content = results.pop('content', None)
self._play_context.become = False
self._play_context.become_method = None
self._connection = self._shared_loader_obj.connection_loader.get('local', self._play_context,
self._connection._new_stdin)
args['data'] = {key: content}
if 'update' not in args:
args['update'] = True
results = merge_hash(
results,
# executes hashivault_write module on localhost
self._execute_module(module_name='hashivault_write', tmp=tmp, task_vars=task_vars, module_args=args)
)
results['invocation']['module_args']['data'] = 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER'
return results