mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #17149 from privateip/plugin-net-config
action plugin net_config will now remove any private result key
This commit is contained in:
commit
fa395bee7b
1 changed files with 17 additions and 5 deletions
|
@ -20,6 +20,7 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import glob
|
||||
import urlparse
|
||||
|
@ -27,6 +28,8 @@ import urlparse
|
|||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.unicode import to_unicode
|
||||
|
||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
||||
|
||||
class ActionModule(ActionBase):
|
||||
|
||||
TRANSFERS_FILES = False
|
||||
|
@ -41,16 +44,24 @@ class ActionModule(ActionBase):
|
|||
except ValueError as exc:
|
||||
return dict(failed=True, msg=exc.message)
|
||||
|
||||
result.update(self._execute_module(module_name=self._task.action,
|
||||
action = self._task.action
|
||||
|
||||
result.update(self._execute_module(module_name=action,
|
||||
module_args=self._task.args, task_vars=task_vars))
|
||||
|
||||
if self._task.args.get('backup_config') and result.get('__backup__'):
|
||||
if self._task.args.get('backup') and result.get('__backup__'):
|
||||
# User requested backup and no error occurred in module.
|
||||
# NOTE: If there is a parameter error, _backup key may not be in results.
|
||||
self._write_backup(task_vars['inventory_hostname'], result['__backup__'])
|
||||
filepath = self._write_backup(task_vars['inventory_hostname'],
|
||||
result['__backup__'])
|
||||
result['backup_path'] = filepath
|
||||
|
||||
if '__backup__' in result:
|
||||
del result['__backup__']
|
||||
|
||||
# strip out any keys that have two leading and two trailing
|
||||
# underscore characters
|
||||
for key in result.keys():
|
||||
if PRIVATE_KEYS_RE.match(key):
|
||||
del result[key]
|
||||
|
||||
return result
|
||||
|
||||
|
@ -69,6 +80,7 @@ class ActionModule(ActionBase):
|
|||
tstamp = time.strftime("%Y-%m-%d@%H:%M:%S", time.localtime(time.time()))
|
||||
filename = '%s/%s_config.%s' % (backup_path, host, tstamp)
|
||||
open(filename, 'w').write(contents)
|
||||
return filename
|
||||
|
||||
def _handle_template(self):
|
||||
src = self._task.args.get('src')
|
||||
|
|
Loading…
Reference in a new issue