mirror of https://github.com/ansible/ansible.git
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 commentpull/50538/head
parent
8f55e817d2
commit
71113ee291
@ -1,50 +0,0 @@
|
|||||||
# This code is part of Ansible, but is an independent component.
|
|
||||||
# This particular file snippet, and this file snippet only, is BSD licensed.
|
|
||||||
# Modules you write using this snippet, which is embedded dynamically by Ansible
|
|
||||||
# still belong to the author of the module, and may assign their own license
|
|
||||||
# to the complete work.
|
|
||||||
#
|
|
||||||
# (c) 2016 Red Hat Inc.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
# are permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright
|
|
||||||
# notice, this list of conditions and the following disclaimer.
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
# this list of conditions and the following disclaimer in the documentation
|
|
||||||
# and/or other materials provided with the distribution.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
||||||
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
||||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
||||||
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
#
|
|
||||||
|
|
||||||
import os
|
|
||||||
import time
|
|
||||||
import glob
|
|
||||||
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
|
|
||||||
|
|
||||||
def write_backup(module, host, contents, encoding='utf-8'):
|
|
||||||
cwd = module._loader.get_basedir()
|
|
||||||
if module._task._role is not None:
|
|
||||||
cwd = module._task._role._role_path
|
|
||||||
|
|
||||||
backup_path = os.path.join(cwd, 'backup')
|
|
||||||
if not os.path.exists(backup_path):
|
|
||||||
os.mkdir(backup_path)
|
|
||||||
for existing_backup in glob.glob('%s/%s_config.*' % (backup_path, host)):
|
|
||||||
os.remove(existing_backup)
|
|
||||||
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(to_text(contents, encoding=encoding))
|
|
||||||
|
|
||||||
return filename
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.aireos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.aruba import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.asa import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.ce import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,89 +0,0 @@
|
|||||||
# (C) 2017 Red Hat Inc.
|
|
||||||
# Copyright (C) 2017 Lenovo.
|
|
||||||
#
|
|
||||||
# GNU General Public License v3.0+
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
#
|
|
||||||
# Contains Action Plugin methods for CNOS Config Module
|
|
||||||
# Lenovo Networking
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.cnos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,95 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# Copyright (c) 2017 Dell Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.dellos10 import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,92 +0,0 @@
|
|||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.dellos6 import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,95 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# Copyright (c) 2017 Dell Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.dellos9 import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,90 +0,0 @@
|
|||||||
# (C) 2017 Red Hat Inc.
|
|
||||||
# Copyright (C) 2017 Lenovo.
|
|
||||||
#
|
|
||||||
# GNU General Public License v3.0+
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
||||||
#
|
|
||||||
# Contains Action Plugin methods for ENOS Config Module
|
|
||||||
# Lenovo Networking
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.enos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,94 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.eos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.ios import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.iosxr import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.ironware import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# (c) 2017, Red Hat, Inc.
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.junos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text, to_bytes
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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__'], encoding='latin-1')
|
|
||||||
result['backup_path'] = filepath
|
|
||||||
|
|
||||||
# strip out any keys that have two leading and two trailing
|
|
||||||
# underscore characters
|
|
||||||
for key in list(result):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,91 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2016 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.netconf import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text, to_bytes
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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__'], encoding='latin-1')
|
|
||||||
result['backup_path'] = filepath
|
|
||||||
|
|
||||||
# strip out any keys that have two leading and two trailing
|
|
||||||
# underscore characters
|
|
||||||
for key in list(result):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.nxos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,93 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2016 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.sros import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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):
|
|
||||||
if PRIVATE_KEYS_RE.match(key):
|
|
||||||
del result[key]
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
@ -1,94 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright 2015 Peter Sprygada <psprygada@ansible.com>
|
|
||||||
#
|
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
from __future__ import (absolute_import, division, print_function)
|
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ansible.plugins.action.vyos import ActionModule as _ActionModule
|
|
||||||
from ansible.module_utils._text import to_text
|
|
||||||
from ansible.module_utils.network.common.backup import write_backup
|
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlsplit
|
|
||||||
from ansible.utils.vars import merge_hash
|
|
||||||
|
|
||||||
|
|
||||||
PRIVATE_KEYS_RE = re.compile('__.+__')
|
|
||||||
|
|
||||||
|
|
||||||
class ActionModule(_ActionModule):
|
|
||||||
|
|
||||||
def run(self, tmp=None, task_vars=None):
|
|
||||||
|
|
||||||
if self._task.args.get('src'):
|
|
||||||
try:
|
|
||||||
self._handle_template()
|
|
||||||
except ValueError as exc:
|
|
||||||
return dict(failed=True, msg=to_text(exc))
|
|
||||||
|
|
||||||
result = super(ActionModule, self).run(tmp, task_vars)
|
|
||||||
del tmp # tmp no longer has any effect
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
def _handle_template(self):
|
|
||||||
src = self._task.args.get('src')
|
|
||||||
working_path = self._get_working_path()
|
|
||||||
|
|
||||||
if os.path.isabs(src) or urlsplit('src').scheme:
|
|
||||||
source = src
|
|
||||||
else:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, 'templates', src)
|
|
||||||
if not source:
|
|
||||||
source = self._loader.path_dwim_relative(working_path, src)
|
|
||||||
|
|
||||||
if not os.path.exists(source):
|
|
||||||
raise ValueError('path specified in src not found')
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(source, 'r') as f:
|
|
||||||
template_data = to_text(f.read())
|
|
||||||
except IOError:
|
|
||||||
return dict(failed=True, msg='unable to load src file')
|
|
||||||
|
|
||||||
# Create a template search path in the following order:
|
|
||||||
# [working_path, self_role_path, dependent_role_paths, dirname(source)]
|
|
||||||
searchpath = [working_path]
|
|
||||||
if self._task._role is not None:
|
|
||||||
searchpath.append(self._task._role._role_path)
|
|
||||||
if hasattr(self._task, "_block:"):
|
|
||||||
dep_chain = self._task._block.get_dep_chain()
|
|
||||||
if dep_chain is not None:
|
|
||||||
for role in dep_chain:
|
|
||||||
searchpath.append(role._role_path)
|
|
||||||
searchpath.append(os.path.dirname(source))
|
|
||||||
self._templar.environment.loader.searchpath = searchpath
|
|
||||||
self._task.args['src'] = self._templar.template(template_data)
|
|
Loading…
Reference in New Issue