aboutsummaryrefslogtreecommitdiff
path: root/ansible/action_plugins
diff options
context:
space:
mode:
authorJeffrey Zhang <zhang.lei.fly@gmail.com>2018-05-15 10:58:50 +0800
committerJeffrey Zhang <zhang.lei.fly@gmail.com>2018-06-12 10:56:45 +0800
commit1db352f007e79f33d969361fa4997b60ef04e9a6 (patch)
treeba625fce5748ae6b37c844fe11fb58b14d612524 /ansible/action_plugins
parentb60468f06ec40530ac3e83a938b1ffdda76f83bb (diff)
downloadkolla-ansible-1db352f007e79f33d969361fa4997b60ef04e9a6.tar.gz
kolla-ansible-1db352f007e79f33d969361fa4997b60ef04e9a6.zip
Support check and diff mode for merge_config and merge_yaml module
Change-Id: Ib2ca736e08f48da88bb74feb5cd1efce3b860ab7 Partially-Implements: blueprint ansible-check-mode
Diffstat (limited to 'ansible/action_plugins')
-rw-r--r--ansible/action_plugins/merge_configs.py41
-rwxr-xr-xansible/action_plugins/merge_yaml.py43
2 files changed, 57 insertions, 27 deletions
diff --git a/ansible/action_plugins/merge_configs.py b/ansible/action_plugins/merge_configs.py
index 556bfa83b..4377dd8c1 100644
--- a/ansible/action_plugins/merge_configs.py
+++ b/ansible/action_plugins/merge_configs.py
@@ -19,7 +19,10 @@
import collections
import inspect
import os
+import shutil
+import tempfile
+from ansible import constants
from ansible.plugins import action
from six import StringIO
@@ -131,22 +134,34 @@ class ActionModule(action.ActionBase):
fakefile = StringIO()
config.write(fakefile)
-
- remote_path = self._connection._shell.join_path(tmp, 'src')
- xfered = self._transfer_data(remote_path, fakefile.getvalue())
+ full_source = fakefile.getvalue()
fakefile.close()
- new_module_args = self._task.args.copy()
- new_module_args.pop('sources', None)
+ local_tempdir = tempfile.mkdtemp(dir=constants.DEFAULT_LOCAL_TMP)
+
+ try:
+ result_file = os.path.join(local_tempdir, 'source')
+ with open(result_file, 'wb') as f:
+ f.write(full_source)
+
+ new_task = self._task.copy()
+ new_task.args.pop('sources', None)
- new_module_args.update(
- dict(
- src=xfered
+ new_task.args.update(
+ dict(
+ src=result_file
+ )
)
- )
- result.update(self._execute_module(module_name='copy',
- module_args=new_module_args,
- task_vars=task_vars,
- tmp=tmp))
+ copy_action = self._shared_loader_obj.action_loader.get(
+ 'copy',
+ task=new_task,
+ connection=self._connection,
+ play_context=self._play_context,
+ loader=self._loader,
+ templar=self._templar,
+ shared_loader_obj=self._shared_loader_obj)
+ result.update(copy_action.run(task_vars=task_vars))
+ finally:
+ shutil.rmtree(local_tempdir)
return result
diff --git a/ansible/action_plugins/merge_yaml.py b/ansible/action_plugins/merge_yaml.py
index 6ad232af8..371905d0d 100755
--- a/ansible/action_plugins/merge_yaml.py
+++ b/ansible/action_plugins/merge_yaml.py
@@ -17,6 +17,8 @@
import inspect
import os
+import shutil
+import tempfile
from yaml import dump
from yaml import safe_load
@@ -28,6 +30,7 @@ except ImportError:
from yaml import Loader # noqa: F401
+from ansible import constants
from ansible.plugins import action
@@ -78,19 +81,31 @@ class ActionModule(action.ActionBase):
# restore original vars
self._templar.set_available_variables(old_vars)
- remote_path = self._connection._shell.join_path(tmp, 'src')
- xfered = self._transfer_data(remote_path,
- dump(output,
- default_flow_style=False))
- new_module_args = self._task.args.copy()
- new_module_args.update(
- dict(
- src=xfered
+ local_tempdir = tempfile.mkdtemp(dir=constants.DEFAULT_LOCAL_TMP)
+
+ try:
+ result_file = os.path.join(local_tempdir, 'source')
+ with open(result_file, 'wb') as f:
+ f.write(dump(output, default_flow_style=False))
+
+ new_task = self._task.copy()
+ new_task.args.pop('sources', None)
+
+ new_task.args.update(
+ dict(
+ src=result_file
+ )
)
- )
- del new_module_args['sources']
- result.update(self._execute_module(module_name='copy',
- module_args=new_module_args,
- task_vars=task_vars,
- tmp=tmp))
+
+ copy_action = self._shared_loader_obj.action_loader.get(
+ 'copy',
+ task=new_task,
+ connection=self._connection,
+ play_context=self._play_context,
+ loader=self._loader,
+ templar=self._templar,
+ shared_loader_obj=self._shared_loader_obj)
+ result.update(copy_action.run(task_vars=task_vars))
+ finally:
+ shutil.rmtree(local_tempdir)
return result