Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
slapos.package
Commits
d2a2521b
Commit
d2a2521b
authored
Sep 08, 2016
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playbook: improve log_parse pluging, fix warning and indendation
parent
372ff44a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
26 deletions
+40
-26
playbook/roles/install-script/files/log_parse
playbook/roles/install-script/files/log_parse
+40
-26
No files found.
playbook/roles/install-script/files/log_parse
View file @
d2a2521b
...
@@ -15,13 +15,13 @@ class CallbackModule(baseModule):
...
@@ -15,13 +15,13 @@ class CallbackModule(baseModule):
"""
"""
logs playbook results, per host, in /var/log/ansible/hosts
logs playbook results, per host, in /var/log/ansible/hosts
"""
"""
log_path = '/var/log/ansible/hosts'
log_path = '/var/log/ansible/hosts'
fd_list = {}
def __init__(self):
def __init__(self):
if ANSIBLE_VERSION > 1:
if ANSIBLE_VERSION > 1:
super(base
Module, self).__init__()
super(Callback
Module, self).__init__()
if not os.path.exists(self.log_path):
if not os.path.exists(self.log_path):
os.makedirs(self.log_path)
os.makedirs(self.log_path)
...
@@ -31,22 +31,33 @@ class CallbackModule(baseModule):
...
@@ -31,22 +31,33 @@ class CallbackModule(baseModule):
if os.path.exists(filepath) and os.path.isfile(filepath):
if os.path.exists(filepath) and os.path.isfile(filepath):
os.unlink(filepath)
os.unlink(filepath)
def writeLog(self, host, category, content):
if not self.fd_list.has_key(category):
self.fd_list[category] = open(
os.path.join(self.log_path, '%s_%s' % (host, category)), "a"
)
self.fd_list[category].write(content + '\n')
def log(self, host, category, data, ignore_errors=False):
def log(self, host, category, data, ignore_errors=False):
if host == "localhost":
host = "127.0.0.1" # keep compatibility
if type(data) == dict:
if type(data) == dict:
if '_ansible_verbose_override' in data:
if '_ansible_verbose_override' in data:
# avoid logging extraneous data
# avoid logging extraneous data
data = {}
return
else:
data = data.copy()
data = data.copy()
data
= json.dumps(data)
content
= json.dumps(data)
if ignore_errors:
if ignore_errors:
category = '%s_IGNORED' % category
category = '%s_IGNORED' % category
path = os.path.join("/var/log/ansible/hosts", '%s_%s' % (host, category))
self.writeLog(host, category, content)
with open(path, "a") as fd:
fd.write(data)
def _stats(self, stats):
fd.write('\n')
for key in self.fd_list:
self.fd_list[key].close()
def runner_on_failed(self, host, res, ignore_errors=False):
def runner_on_failed(self, host, res, ignore_errors=False):
self.log(host, 'FAILED', res, ignore_errors)
self.log(host, 'FAILED', res, ignore_errors)
...
@@ -69,4 +80,7 @@ class CallbackModule(baseModule):
...
@@ -69,4 +80,7 @@ class CallbackModule(baseModule):
def playbook_on_not_import_for_host(self, host, missing_file):
def playbook_on_not_import_for_host(self, host, missing_file):
self.log(host, 'NOTIMPORTED', missing_file)
self.log(host, 'NOTIMPORTED', missing_file)
def playbook_on_stats(self, stats):
self._stats(stats)
EOF
EOF
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment