From 7a9b8e43da14776e71a9a989d6436ec3b1d19695 Mon Sep 17 00:00:00 2001 From: Wolfgang Karall Date: Wed, 13 Apr 2016 20:05:50 +0200 Subject: [PATCH] get_mount_facts -- find bind mounts and add info to options field (#12036) * get_mount_facts -- find bind mounts and add info to options field * get_mount_facts -- only run findmnt if get_bin_path() finds the binary --- lib/ansible/module_utils/facts.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 6ae21c54a6c..bf286c2eb67 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1083,6 +1083,19 @@ class LinuxHardware(Hardware): def get_mount_facts(self): uuids = dict() self.facts['mounts'] = [] + bind_mounts = [] + findmntPath = module.get_bin_path("findmnt") + if findmntPath: + rc, out, err = module.run_command("%s -lnur" % ( findmntPath ), use_unsafe_shell=True) + if rc == 0: + # find bind mounts, in case /etc/mtab is a symlink to /proc/mounts + for line in out.split('\n'): + fields = line.rstrip('\n').split() + if(len(fields) < 2): + continue + if(re.match(".*\]",fields[1])): + bind_mounts.append(fields[0]) + mtab = get_file_content('/etc/mtab', '') for line in mtab.split('\n'): fields = line.rstrip('\n').split() @@ -1101,6 +1114,11 @@ class LinuxHardware(Hardware): uuid = out.strip() uuids[fields[0]] = uuid + if fields[1] in bind_mounts: + # only add if not already there, we might have a plain /etc/mtab + if not re.match(".*bind.*", fields[3]): + fields[3] += ",bind" + self.facts['mounts'].append( {'mount': fields[1], 'device':fields[0],