Skip to content

Instantly share code, notes, and snippets.

@kusw3
Created January 29, 2019 09:46
Show Gist options
  • Save kusw3/a4f4828d980dd2bd524482310cfe796d to your computer and use it in GitHub Desktop.
Save kusw3/a4f4828d980dd2bd524482310cfe796d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
"""
Shitty script to parse individual files containing a json type salt-ssh output to a yum -q check-update command.
CSV is generated with the id taken from a list and each of packages marked to be udpated
"""
import os
import sys
import json
import argparse
if __name__ == '__main__':
try:
basedir = sys.argv[1]
except IndexError:
basedir = '.'
f_list = open("serv_patch_list.txt", "r")
for container in f_list:
patch_f = open("patch_lists/{}_patches.txt".format(container.rstrip()), "r")
data = json.loads(patch_f.read())
for key,value in data.items():
if value['retcode'] == 100:
for line in value['stdout'].splitlines():
if 'password' in line:
continue
elif line.rstrip() == '':
continue
else:
print("{},".format(key) + ",".join(line.split()))
else:
print(value['stderr'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment