repquota output as nice JSON
The following script at /etc/ansible/facts.d/repquota.fact
:
#!/usr/bin/env bash
set -e -o pipefail
repquota /home -O xml | xq -Mc
Results in Ansible facts like this:
ansible_facts:
ansible_local:
repquota:
repquota:
Report:
'@dev': /dev/xvda4
'@type': user
BlockGraceTime: '24:00'
InodeGraceTime: '24:00'
Quota:
- '@user': root
FileLimits:
'@grace': ''
'@hard': '0'
'@soft': '0'
'@used': '45'
QuotaStatus:
'@block': ok
'@inode': ok
blockLimits:
'@grace': ''
'@hard': '0'
'@soft': '0'
'@used': '188'
- '@user': foobar
FileLimits:
'@grace': ''
'@hard': '209715'
'@soft': '190887'
'@used': '69'
QuotaStatus:
'@block': ok
'@inode': ok
blockLimits:
'@grace': ''
'@hard': '1048576'
'@soft': '954437'
'@used': '364'
- '@user': mattermost
FileLimits:
'@grace': ''
'@hard': '0'
'@soft': '0'
'@used': '7'
QuotaStatus:
'@block': ok
'@inode': ok
blockLimits:
'@grace': ''
'@hard': '0'
'@soft': '0'
'@used': '28'
Which is clearly horrible... jq
or something needs to do a better job with the XML that repquota
outputs:
<?xml version="1.0"?>
<repquota>
<Report type='user' dev='/dev/xvda4'>
<BlockGraceTime>24:00</BlockGraceTime>
<InodeGraceTime>24:00</InodeGraceTime>
<Quota user='root'>
<QuotaStatus block='ok' inode='ok' />
<blockLimits used='188' soft='0' hard='0' grace='' />
<FileLimits used='45' soft='0' hard='0' grace='' />
</Quota>
<Quota user='foobar'>
<QuotaStatus block='ok' inode='ok' />
<blockLimits used='364' soft='954437' hard='1048576' grace='' />
<FileLimits used='69' soft='190887' hard='209715' grace='' />
</Quota>
</Report>
</repquota>