Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #python security-check-8.py -i /etc/ansible/inventories/generic/static/local/local.yml -f /etc/ansible/playbooks/patchman/log-check.yml
- import re
- import json
- from datetime import datetime as dt
- import subprocess
- import argparse
- import csv
- def gencsv(out):
- with open("out1000.csv","w+") as fl:
- temp=csv.writer(fl, delimiter=",")
- temp.writerow(["IP", "HOSTNAME" , "OS VERSION" , "CPU USAGE", "MEMORY USAGE", "ANSIBLE VERSION"])
- ips=[]
- nid=[]
- out = out.decode("utf-8")
- print(out)
- xx = out.split("\n")
- for nli in xx:
- if "ansible_default_ipv4.address" in nli:
- ipx=nli.split(":")[1]
- ips.append(ipx.replace('"',''))
- for line in xx:
- if "ansible_nodename" in line:
- node = line.split(":")[1]
- nid.append(node.replace('"',''))
- out= out.replace("\n","")
- for rowips in ips:
- for nidrow in nid:
- temp.writerow(["%s" %(rowips), "%s" %(rownid)])
- #[u' controller', u' an1', u' controller', u' an1']
- """ for hs in nid:
- optx='ok: [%s] => { "msg": "os version : "}'%hs.replace(" ","")
- solx='ok: [%s] => { "msg": "cpu usage: "}'%hs.replace(" ","")
- zkx='ok: [%s] => { "msg": "memory usage: "}'%hs.replace(" ","")
- ans='ok: [%s] => { "msg": "ansible version: "}'%hs.replace(" ","")
- ipx = ips[int(nid.index(hs))]
- opt = ""
- sol = ""
- zk = ""
- if optx in out:
- opt = ""
- else:
- opt = ""
- if solx in out:
- sol = ""
- else:
- sol = ""
- if zkx in out:
- zk = ""
- else:
- zk = ""
- if ans in out:
- ans = ""
- else:
- ans = ""
- # temp.writerow(["%s","%s","%s","%s","%s","%s" %(ipx,hs,opt,sol,zk,ans)])"""
- # temp.writerow(["%s" %(ipx), "%s" %(hst)])
- #store but its correct?
- #no kust controller must say...can u see difference with sample.xls
- def execute(fur,sur):
- cmd2 = "ansible-playbook -i %s %s"%(fur,sur)
- p = subprocess.Popen(cmd2, stdout=subprocess.PIPE, shell=True)
- out, err = p.communicate()
- return(out)
- if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument("-i")
- parser.add_argument("-f")
- args = parser.parse_args()
- if (args.i is not None) and (args.f is not None):
- out = execute(args.i,args.f)
- gencsv(out)
- else:
- print("Missing arguments .")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement