mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
4822c2caa5
commit
7a9b8e43da
1 changed files with 18 additions and 0 deletions
|
@ -1083,6 +1083,19 @@ class LinuxHardware(Hardware):
|
||||||
def get_mount_facts(self):
|
def get_mount_facts(self):
|
||||||
uuids = dict()
|
uuids = dict()
|
||||||
self.facts['mounts'] = []
|
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', '')
|
mtab = get_file_content('/etc/mtab', '')
|
||||||
for line in mtab.split('\n'):
|
for line in mtab.split('\n'):
|
||||||
fields = line.rstrip('\n').split()
|
fields = line.rstrip('\n').split()
|
||||||
|
@ -1101,6 +1114,11 @@ class LinuxHardware(Hardware):
|
||||||
uuid = out.strip()
|
uuid = out.strip()
|
||||||
uuids[fields[0]] = uuid
|
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(
|
self.facts['mounts'].append(
|
||||||
{'mount': fields[1],
|
{'mount': fields[1],
|
||||||
'device':fields[0],
|
'device':fields[0],
|
||||||
|
|
Loading…
Reference in a new issue