2015-04-02 23:21:45 +02:00
|
|
|
# (c) 2015, Brian Coca <briancoca+dev@gmail.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
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2018-01-23 02:44:22 +01:00
|
|
|
from ansible.errors import AnsibleError, AnsibleAction, _AnsibleActionDone, AnsibleActionFail
|
2016-09-07 07:54:17 +02:00
|
|
|
from ansible.module_utils._text import to_native
|
2017-07-15 01:44:58 +02:00
|
|
|
from ansible.module_utils.parsing.convert_bool import boolean
|
2015-04-02 23:21:45 +02:00
|
|
|
from ansible.plugins.action import ActionBase
|
|
|
|
|
2015-10-23 01:07:26 +02:00
|
|
|
|
2015-04-02 23:21:45 +02:00
|
|
|
class ActionModule(ActionBase):
|
|
|
|
|
2018-01-16 06:15:04 +01:00
|
|
|
TRANSFERS_FILES = True
|
|
|
|
|
2015-10-23 01:07:26 +02:00
|
|
|
def run(self, tmp=None, task_vars=None):
|
|
|
|
if task_vars is None:
|
|
|
|
task_vars = dict()
|
|
|
|
|
|
|
|
result = super(ActionModule, self).run(tmp, task_vars)
|
2018-02-08 00:11:36 +01:00
|
|
|
del tmp # tmp no longer has any effect
|
2018-01-19 00:51:42 +01:00
|
|
|
|
2017-06-02 13:14:11 +02:00
|
|
|
src = self._task.args.get('src', None)
|
2017-07-15 01:44:58 +02:00
|
|
|
remote_src = boolean(self._task.args.get('remote_src', 'no'), strict=False)
|
2015-04-02 23:21:45 +02:00
|
|
|
|
2016-06-28 23:23:30 +02:00
|
|
|
try:
|
2018-01-16 06:15:04 +01:00
|
|
|
if src is None:
|
|
|
|
raise AnsibleActionFail("src is required")
|
|
|
|
elif remote_src:
|
|
|
|
# everything is remote, so we just execute the module
|
|
|
|
# without changing any of the module arguments
|
2018-01-23 02:44:22 +01:00
|
|
|
raise _AnsibleActionDone(result=self._execute_module(task_vars=task_vars))
|
2015-04-02 23:21:45 +02:00
|
|
|
|
2018-01-16 06:15:04 +01:00
|
|
|
try:
|
|
|
|
src = self._find_needle('files', src)
|
|
|
|
except AnsibleError as e:
|
|
|
|
raise AnsibleActionFail(to_native(e))
|
2015-04-02 23:21:45 +02:00
|
|
|
|
2018-02-15 18:01:02 +01:00
|
|
|
tmp_src = self._connection._shell.join_path(self._connection._shell.tmpdir, os.path.basename(src))
|
2018-01-16 06:15:04 +01:00
|
|
|
self._transfer_file(src, tmp_src)
|
2018-02-19 18:07:06 +01:00
|
|
|
self._fixup_perms2((self._connection._shell.tmpdir, tmp_src))
|
2015-04-02 23:21:45 +02:00
|
|
|
|
2018-01-16 06:15:04 +01:00
|
|
|
new_module_args = self._task.args.copy()
|
|
|
|
new_module_args.update(
|
|
|
|
dict(
|
|
|
|
src=tmp_src,
|
|
|
|
)
|
2015-04-02 23:21:45 +02:00
|
|
|
)
|
|
|
|
|
2018-01-16 06:15:04 +01:00
|
|
|
result.update(self._execute_module('patch', module_args=new_module_args, task_vars=task_vars))
|
|
|
|
except AnsibleAction as e:
|
|
|
|
result.update(e.result)
|
|
|
|
finally:
|
2018-02-15 18:01:02 +01:00
|
|
|
self._remove_tmp_path(self._connection._shell.tmpdir)
|
2015-10-23 01:07:26 +02:00
|
|
|
return result
|