mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-06 16:34:02 -07:00
Fix backup issue in network config modules and network action plugins common code refactor (#50301)
* Fix backup issue in network config modules * Fix `get_working_path` not found issue introduced due to backup config code refactor (PR #50208) * Further refactor config related action plugins to minimize duplicate code * Remove unwated imports in config action plugins * Add common network class for action plugin and related code refactor * Fix review comment
This commit is contained in:
parent
8f55e817d2
commit
71113ee291
50 changed files with 168 additions and 2347 deletions
|
@ -19,34 +19,16 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from ansible.plugins.action.normal import ActionModule as _ActionModule
|
||||
from ansible.module_utils.network.common.backup import write_backup
|
||||
from ansible.plugins.action.network import ActionModule as ActionNetworkModule
|
||||
|
||||
|
||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
||||
|
||||
|
||||
class ActionModule(_ActionModule):
|
||||
class ActionModule(ActionNetworkModule):
|
||||
|
||||
def run(self, tmp=None, task_vars=None):
|
||||
del tmp # tmp no longer has any effect
|
||||
|
||||
self._config_module = True
|
||||
if self._play_context.connection != 'network_cli':
|
||||
return {'failed': True, 'msg': 'Connection type %s is not valid for cli_config module' % self._play_context.connection}
|
||||
|
||||
result = super(ActionModule, self).run(task_vars=task_vars)
|
||||
|
||||
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.
|
||||
filepath = write_backup(self, task_vars['inventory_hostname'], result['__backup__'])
|
||||
result['backup_path'] = filepath
|
||||
|
||||
# strip out any keys that have two leading and two trailing
|
||||
# underscore characters
|
||||
for key in list(result.keys()):
|
||||
if PRIVATE_KEYS_RE.match(key):
|
||||
del result[key]
|
||||
|
||||
return result
|
||||
return super(ActionModule, self).run(task_vars=task_vars)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue