-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquotatool.fact.j2
29 lines (24 loc) · 975 Bytes
/
quotatool.fact.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
# {{ ansible_managed }}
set -euo pipefail
jo=$(type -P jo || echo "absent")
quota=$(type -P quota || echo "absent")
quotatool=$(type -P quotatool || echo "absent")
if [[ "${quota}" != "absent" ]]; then
quotacheck=$("${quota}" -f {{ quota_dir | quote }} > /dev/null && echo "pass" || echo "fail")
if [[ "${quotatool}" != "absent" && "${quotacheck}" == "pass" ]]; then
# quotatool uses -n for dry run so the value isn't changed and only the old quota value is saved
block_grace=$("${quotatool}" -v -n -u -b -t 10 {{ quota_dir | quote }} 2>&1 | tail -n1 | awk '{ print $4 }')
inode_grace=$("${quotatool}" -v -n -u -i -t 10 {{ quota_dir | quote }} 2>&1 | tail -n1 | awk '{ print $4 }')
"${jo}" state=present block_grace="${block_grace}" inode_grace="${inode_grace}"
else
"${jo}" state=absent
fi
else
if [[ "${jo}" != "absent" ]]; then
"${jo}" state=absent
else
echo '{"state":"absent"}'
fi
fi
# vim: syntax=bash