summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-21 11:19:55 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-21 13:55:18 +0800
commitda1b699e26f5b876c784ced944ec625b17511b7a (patch)
treebef7718ea0ed4be214b60a8b0af4245cc4137e75
parenta00a76746646619a1fbd9246f23d78eac5ce3b56 (diff)
Set default folder for dump data
Change-Id: I2b96bcf369b13a679a417d78ebca19b3e63155e2 Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
-rw-r--r--qtip/ansible_library/plugins/action/collect.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/qtip/ansible_library/plugins/action/collect.py b/qtip/ansible_library/plugins/action/collect.py
index 17439710..0ae3477d 100644
--- a/qtip/ansible_library/plugins/action/collect.py
+++ b/qtip/ansible_library/plugins/action/collect.py
@@ -29,7 +29,9 @@ class ActionModule(ActionBase):
dump = self._task.args.get('dump')
if dump is not None:
- dump_facts(task_vars['inventory_hostname'], [{'name': dump, 'content': string}], task_vars['qtip_results'])
+ root = task_vars.get('qtip_results', 'results')
+ base = task_vars.get('dump_base', 'dump')
+ dump_facts(task_vars['inventory_hostname'], [{'name': dump, 'content': string}], root, base)
return collect(patterns, string)
@@ -50,9 +52,9 @@ def collect(patterns, string):
return captured
-def dump_facts(hostname, facts, root='results'):
- dump_root = os.path.join(root, hostname)
- if not os.path.exists(dump_root):
- os.mkdir(dump_root)
- return [{'name': fact['name'], 'result': open(os.path.join(dump_root, fact['name']), 'w+').write(fact['content'])}
+def dump_facts(hostname, facts, root, base):
+ dest = os.path.join(root, hostname, base)
+ if not os.path.exists(dest):
+ os.makedirs(dest)
+ return [{'name': fact['name'], 'result': open(os.path.join(dest, fact['name']), 'w+').write(fact['content'])}
for fact in facts]