aboutsummaryrefslogtreecommitdiffstats
path: root/qtip
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-12 15:37:24 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2017-04-12 16:09:49 +0800
commit9c274969f1d8cee2012ec16a21ad85d20d585c84 (patch)
treeb86f2ebb4b43985ccc7507b03d52c7693fa3a68f /qtip
parente7b739f9a202ebcee56e1707161477829ce6a683 (diff)
Dump collected facts
Change-Id: Id0b7b2e94016a73ffcaa2d737af1ca33230b3662 Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'qtip')
-rw-r--r--qtip/ansible_library/plugins/action/collect.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/qtip/ansible_library/plugins/action/collect.py b/qtip/ansible_library/plugins/action/collect.py
index 88ad0e35..26e813b8 100644
--- a/qtip/ansible_library/plugins/action/collect.py
+++ b/qtip/ansible_library/plugins/action/collect.py
@@ -10,6 +10,7 @@
##############################################################################
from collections import defaultdict
+import os
import re
from ansible.plugins.action import ActionBase
@@ -26,6 +27,10 @@ class ActionModule(ActionBase):
string = self._task.args.get('string')
patterns = self._task.args.get('patterns')
+ dump = self._task.args.get('dump')
+ if dump is not None:
+ dump_facts(task_vars['inventory_hostname'], [{'name': 'inxi.log', 'content': string}])
+
return collect(patterns, string)
@@ -43,3 +48,11 @@ def collect(patterns, string):
captured[key].append(value)
return captured
+
+
+def dump_facts(hostname, facts):
+ dump_root = os.path.join('dump', 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'])}
+ for fact in facts]