Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problems Formatting JSON
#1
I need to generate reports from JSON files that are output from SaltStack jobs. I have no control over the format of the JSON files, they are what they are, my job is to format them.

Here is the raw JSON output:

Quote:{"master1":{"server1":{"fun":"cmd.run","return":"/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2","job_source":"raas","has_errors":false,"tgt_uuid":"9f433144-4519-11e8-87db-00505694fa60","user":"user1","jid":"20180504012514377668","low":{"fun":"cmd.run","tgt_type":"compound","tgt":"[email protected],server2,server3,server4,server5,server6,server7,server8,server9,server10,server11","user":"user1","masters":[],"pillars":[],"cmd":"local","arg":{"arg":["fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"]},"tgt_uuid":"9f433144-4519-11e8-87db-00505694fa60"},"job_uuid":null,"master":"master1","fun_args":["fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"],"minion_id":"server1","alter_time":"2018-05-04T01:25:24.760419","full_ret":{"fun":"cmd.run","return":"/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2","_stamp":"2018-05-04T01:25:51.599959","retcode":0,"jid":"20180504012514377668","id":"server1","cmd":"_return","fun_args":["fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"],"success":true,"_master_path":["master1.mydomain.com_master"]},"master_uuid":"fbe17756-287e-11e8-8bfc-00505694fa60","cmd":"local"}},"master2":{"server7":{"fun":"cmd.run","return":"/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 6.6G 12G 38% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2","job_source":"raas","has_errors":false,"tgt_uuid":"9f433144-4519-11e8-87db-00505694fa60","user":"user1","jid":"20180504012514377668","low":{"fun":"cmd.run","tgt_type":"compound","tgt":"[email protected],server2,server3,server4,server5,server6,server7,server8,server9,server10,server11","user":"user1","masters":[],"pillars":[],"cmd":"local","arg":{"arg":["fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"]},"tgt_uuid":"9f433144-4519-11e8-87db-00505694fa60"},"job_uuid":null,"master":"master2","fun_args":["fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"],"minion_id":"server7","alter_time":"2018-05-04T01:36:04.394079","full_ret":{"fun":"cmd.run","return":"/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 6.6G 12G 38% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2","_stamp":"2018-05-04T01:27:13.160514","retcode":0,"jid":"20180504012514377668","id":"server7","cmd":"_return","fun_args":["fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"],"success":true,"_master_path":["master2.mydomain.com_master"]},"master_uuid":"7c61c378-2c7a-11e8-aa08-005056b6af3a","cmd":"local"}}}

Here is the pretty JSON output if that helps:
Quote:{
"master1": {
"server1": {
"fun": "cmd.run",
"return": "/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2",
"job_source": "raas",
"has_errors": false,
"tgt_uuid": "9f433144-4519-11e8-87db-00505694fa60",
"user": "user1",
"jid": "20180504012514377668",
"low": {
"fun": "cmd.run",
"tgt_type": "compound",
"tgt": "[email protected],server2,server3,server4,server5,server6,server7,server8,server9,server10,server11",
"user": "user1",
"masters": [],
"pillars": [],
"cmd": "local",
"arg": {
"arg": [
"fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"
]
},
"tgt_uuid": "9f433144-4519-11e8-87db-00505694fa60"
},
"job_uuid": null,
"master": "master1",
"fun_args": [
"fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"
],
"minion_id": "server1",
"alter_time": "2018-05-04T01:25:24.760419",
"full_ret": {
"fun": "cmd.run",
"return": "/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2",
"_stamp": "2018-05-04T01:25:51.599959",
"retcode": 0,
"jid": "20180504012514377668",
"id": "server1",
"cmd": "_return",
"fun_args": [
"fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"
],
"success": true,
"_master_path": [
"master1.mydomain.com_master"
]
},
"master_uuid": "fbe17756-287e-11e8-8bfc-00505694fa60",
"cmd": "local"
}
},
"master2": {
"server7": {
"fun": "cmd.run",
"return": "/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 6.6G 12G 38% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2",
"job_source": "raas",
"has_errors": false,
"tgt_uuid": "9f433144-4519-11e8-87db-00505694fa60",
"user": "user1",
"jid": "20180504012514377668",
"low": {
"fun": "cmd.run",
"tgt_type": "compound",
"tgt": "[email protected],server2,server3,server4,server5,server6,server7,server8,server9,server10,server11",
"user": "user1",
"masters": [],
"pillars": [],
"cmd": "local",
"arg": {
"arg": [
"fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"
]
},
"tgt_uuid": "9f433144-4519-11e8-87db-00505694fa60"
},
"job_uuid": null,
"master": "master2",
"fun_args": [
"fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"
],
"minion_id": "server7",
"alter_time": "2018-05-04T01:36:04.394079",
"full_ret": {
"fun": "cmd.run",
"return": "/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 6.6G 12G 38% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2",
"_stamp": "2018-05-04T01:27:13.160514",
"retcode": 0,
"jid": "20180504012514377668",
"id": "server7",
"cmd": "_return",
"fun_args": [
"fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab"
],
"success": true,
"_master_path": [
"master2.mydomain.com_master"
]
},
"master_uuid": "7c61c378-2c7a-11e8-aa08-005056b6af3a",
"cmd": "local"
}
}
}

What I need to do is generate a report that looks like this:

Salt Master: master1
Minion: server1
Output:
/dev/sda1 * 63 16723664 8361801 83 Linux
/dev/sda2 16723665 33447329 8361832+ 83 Linux
/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris
/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM
/dev/sdb1 63 60806024 30402981 8e Linux LVM
/dev/sdc1 63 146785904 73392921 8e Linux LVM
Disk /dev/sda: 44.0 GB, 44023414784 bytes
Disk /dev/sdb: 31.1 GB, 31138512896 bytes
Disk /dev/sdc: 75.2 GB, 75161927680 bytes

PV VG Fmt Attr PSize PFree
/dev/sda4 rootvg lvm2 a-- 21.04g 40.00m
/dev/sdb1 appvg lvm2 a-- 28.99g 8.99g
/dev/sdc1 appvg lvm2 a-- 69.99g 1.99g

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver

/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2

Salt Master: master2
Minion: server7
Output:
/dev/sda1 * 63 16723664 8361801 83 Linux
/dev/sda2 16723665 33447329 8361832+ 83 Linux
/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris
/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM
/dev/sdb1 63 60806024 30402981 8e Linux LVM
/dev/sdc1 63 146785904 73392921 8e Linux LVM
Disk /dev/sda: 44.0 GB, 44023414784 bytes
Disk /dev/sdb: 31.1 GB, 31138512896 bytes
Disk /dev/sdc: 75.2 GB, 75161927680 bytes

PV VG Fmt Attr PSize PFree
/dev/sda4 rootvg lvm2 a-- 21.04g 40.00m
/dev/sdb1 appvg lvm2 a-- 28.99g 8.99g
/dev/sdc1 appvg lvm2 a-- 69.99g 1.99g

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver

/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2

So far I have managed to get the Master Server and Minion data. Here is the code for that:
#!/usr/local/bin/python3.6

import json
import argparse

# Create the CLI parser
parser = argparse.ArgumentParser(description='Create a report from a Salt JSON file/URL', formatter_class=argparse.RawTextHelpFormatter)

# Get the JSON input
parser.add_argument('json_input', help='The file or URL to the JSON input')

args = parser.parse_args()

json_in = args.json_input

with open(json_in, 'r') as stream:
	data = json.load(stream)
	
	for SaltMaster in data:
		# Get the minion items
		for minion in data[SaltMaster]:
			print('Salt Master: ', SaltMaster)
			print('Minion: ', minion)
Here is the output from that code:
Output:
Salt Master: master1 Minion: server1 Salt Master: master2 Minion: server7
I want to get the date from the full_ret key so I added this code:
for minion in data[SaltMaster]:
			dataout = (minion, data[SaltMaster][minion])
			print('Salt Master: ', SaltMaster)
			print('Minion: ', minion)
			for full_ret in dataout[full_ret]:
				print(full_ret)
Now I get an error:
Error:
Traceback (most recent call last): File "./test_json.py", line 29, in <module> for full_ret in dataout[full_ret]: NameError: name 'full_ret' is not defined
I can print the value of the dataout variable:
Output:
The output is: Salt Master: master1 Minion: server1 ('server1', {'fun': 'cmd.run', 'return': '/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2', 'job_source': 'raas', 'has_errors': False, 'tgt_uuid': '9f433144-4519-11e8-87db-00505694fa60', 'user': 'user1', 'jid': '20180504012514377668', 'low': {'fun': 'cmd.run', 'tgt_type': 'compound', 'tgt': '[email protected],server2,server3,server4,server5,server6,server7,server8,server9,server10,server11', 'user': 'user1', 'masters': [], 'pillars': [], 'cmd': 'local', 'arg': {'arg': ['fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab']}, 'tgt_uuid': '9f433144-4519-11e8-87db-00505694fa60'}, 'job_uuid': None, 'master': 'master1', 'fun_args': ['fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab'], 'minion_id': 'server1', 'alter_time': '2018-05-04T01:25:24.760419', 'full_ret': {'fun': 'cmd.run', 'return': '/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 7.5G 11G 42% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2', '_stamp': '2018-05-04T01:25:51.599959', 'retcode': 0, 'jid': '20180504012514377668', 'id': 'server1', 'cmd': '_return', 'fun_args': ['fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab'], 'success': True, '_master_path': ['master1.mydomain.com_master']}, 'master_uuid': 'fbe17756-287e-11e8-8bfc-00505694fa60', 'cmd': 'local'}) Salt Master: master2 Minion: server7 ('server7', {'fun': 'cmd.run', 'return': '/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 6.6G 12G 38% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2', 'job_source': 'raas', 'has_errors': False, 'tgt_uuid': '9f433144-4519-11e8-87db-00505694fa60', 'user': 'user1', 'jid': '20180504012514377668', 'low': {'fun': 'cmd.run', 'tgt_type': 'compound', 'tgt': '[email protected],server2,server3,server4,server5,server6,server7,server8,server9,server10,server11', 'user': 'user1', 'masters': [], 'pillars': [], 'cmd': 'local', 'arg': {'arg': ['fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab']}, 'tgt_uuid': '9f433144-4519-11e8-87db-00505694fa60'}, 'job_uuid': None, 'master': 'master2', 'fun_args': ['fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab'], 'minion_id': 'server7', 'alter_time': '2018-05-04T01:36:04.394079', 'full_ret': {'fun': 'cmd.run', 'return': '/dev/sda1 * 63 16723664 8361801 83 Linux\n/dev/sda2 16723665 33447329 8361832+ 83 Linux\n/dev/sda3 33447330 41849324 4200997+ 82 Linux swap / Solaris\n/dev/sda4 41849325 85979879 22065277+ 8e Linux LVM\n/dev/sdb1 63 60806024 30402981 8e Linux LVM\n/dev/sdc1 63 146785904 73392921 8e Linux LVM\nDisk /dev/sda: 44.0 GB, 44023414784 bytes\nDisk /dev/sdb: 31.1 GB, 31138512896 bytes\nDisk /dev/sdc: 75.2 GB, 75161927680 bytes\n\n PV VG Fmt Attr PSize PFree \n /dev/sda4 rootvg lvm2 a-- 21.04g 40.00m\n /dev/sdb1 appvg lvm2 a-- 28.99g 8.99g\n /dev/sdc1 appvg lvm2 a-- 69.99g 1.99g\n\nFilesystem Size Used Avail Use% Mounted on\n/dev/mapper/appvg-appserver_lv 18G 6.6G 12G 38% /appserver\n\n/dev/appvg/appserver_lv /appserver ext3 acl,user_xattr 1 2', '_stamp': '2018-05-04T01:27:13.160514', 'retcode': 0, 'jid': '20180504012514377668', 'id': 'server7', 'cmd': '_return', 'fun_args': ['fdisk -l | grep /dev/sd | sort;echo;pvs;echo;df -hP /appserver;echo;grep /appserver /etc/fstab'], 'success': True, '_master_path': ['master2.mydomain.com_master']}, 'master_uuid': '7c61c378-2c7a-11e8-aa08-005056b6af3a', 'cmd': 'local'})
When I check the datatype for dataout I see:
Output:
<class 'tuple'>
I'm pretty sure that the problem is that I can iterate through dataout because it is a tuple. I can't figure out how to parse the tuple data to get the full_ret data. Anyone have some suggestions?
Reply
#2
It should be for full_ret in dataout["full_ret"]: (note the quotes).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting json cleanly Daring_T 0 307 Nov-19-2020, 10:39 PM
Last Post: Daring_T

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020