Commit 0ee609e5 authored by Alain Takoudjou's avatar Alain Takoudjou

vm-bootstrap: upload empty FAILED file when there is no failures

parent 9359cf97
...@@ -5,5 +5,5 @@ ...@@ -5,5 +5,5 @@
- name: Add a periodical upload of logs and result - name: Add a periodical upload of logs and result
cron: name="Upload ansible files to http server" cron: name="Upload ansible files to http server"
minute="*/7" minute="*/7"
job="bash -lc /usr/local/bin/ansible-upload-vm-logs http://10.0.2.100/ /var/log/vm-bootstrap.log > /var/log/ansible-upload.log" job="/usr/local/bin/ansible-upload-vm-logs http://10.0.2.100/ /var/log/vm-bootstrap.log > /var/log/ansible-upload.log"
...@@ -8,9 +8,11 @@ class uploader(): ...@@ -8,9 +8,11 @@ class uploader():
log_path = '/var/log/ansible/hosts' log_path = '/var/log/ansible/hosts'
url = '' url = ''
host = '127.0.0.1'
def __init__(self, url='http://10.0.2.100/'): def __init__(self, url='http://10.0.2.100/', host='127.0.0.1'):
self.url = url self.url = url
self.host = host
def upload_file(self, file_name, content, override=False): def upload_file(self, file_name, content, override=False):
values = {'path': file_name, 'content': content} values = {'path': file_name, 'content': content}
...@@ -20,6 +22,7 @@ class uploader(): ...@@ -20,6 +22,7 @@ class uploader():
return result return result
def upload_result(self): def upload_result(self):
has_failure = False
for filename in os.listdir(self.log_path): for filename in os.listdir(self.log_path):
filepath = os.path.join(self.log_path, filename) filepath = os.path.join(self.log_path, filename)
to_path = 'ansible/%s' % filename to_path = 'ansible/%s' % filename
...@@ -29,6 +32,12 @@ class uploader(): ...@@ -29,6 +32,12 @@ class uploader():
content = ','.join(fd.readlines()) content = ','.join(fd.readlines())
r = self.upload_file(to_path, '[%s]' % content, True) r = self.upload_file(to_path, '[%s]' % content, True)
print 'Content uploaded to %s' % to_path, r print 'Content uploaded to %s' % to_path, r
if filename.endswith('FAILED'):
has_failure = True
if not has_failure:
to_path = 'ansible/%s_FAILED' % self.host
r = self.upload_file(to_path, '[]', True)
print 'Content uploaded to %s' % to_path, r
def readFileFrom(self, f, lastPosition, limit=20000): def readFileFrom(self, f, lastPosition, limit=20000):
""" """
...@@ -83,7 +92,7 @@ if __name__ == "__main__": ...@@ -83,7 +92,7 @@ if __name__ == "__main__":
if len(sys.argv) >= 3: if len(sys.argv) >= 3:
ansible_log = sys.argv[2] ansible_log = sys.argv[2]
uploader = uploader() uploader = uploader(url=url)
state_file = "/opt/.ansible_log.state" state_file = "/opt/.ansible_log.state"
log_destination = "ansible/vm-bootstrap.log" log_destination = "ansible/vm-bootstrap.log"
current_state = 0 current_state = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment