def get_mount_info(self, mount, device, uuids): mount_size = get_mount_size(mount) # _udevadm_uuid is a fallback for versions of lsblk <= 2.23 that don't have --paths # see _run_lsblk() above # https://github.com/assible/assible/issues/36077 uuid = uuids.get(device, self._udevadm_uuid(device)) return mount_size, uuid
def get_mount_facts(self): mount_facts = {} mount_facts['mounts'] = [] mounts = [] # AIX does not have mtab but mount command is only source of info (or to use # api calls to get same info) mount_path = self.module.get_bin_path('mount') rc, mount_out, err = self.module.run_command(mount_path) if mount_out: for line in mount_out.split('\n'): fields = line.split() if len(fields) != 0 and fields[ 0] != 'node' and fields[0][0] != '-' and re.match( '^/.*|^[a-zA-Z].*|^[0-9].*', fields[0]): if re.match('^/', fields[0]): # normal mount mount = fields[1] mount_info = { 'mount': mount, 'device': fields[0], 'fstype': fields[2], 'options': fields[6], 'time': '%s %s %s' % (fields[3], fields[4], fields[5]) } mount_info.update(get_mount_size(mount)) else: # nfs or cifs based mount # in case of nfs if no mount options are provided on command line # add into fields empty string... if len(fields) < 8: fields.append("") mount_info = { 'mount': fields[2], 'device': '%s:%s' % (fields[0], fields[1]), 'fstype': fields[3], 'options': fields[7], 'time': '%s %s %s' % (fields[4], fields[5], fields[6]) } mounts.append(mount_info) mount_facts['mounts'] = mounts return mount_facts
def get_mount_facts(self): mount_facts = {} mount_facts['mounts'] = [] fstab = get_file_content('/etc/fstab') if fstab: for line in fstab.splitlines(): if line.startswith('#') or line.strip() == '': continue fields = re.sub(r'\s+', ' ', line).split() mount_statvfs_info = get_mount_size(fields[1]) mount_info = { 'mount': fields[1], 'device': fields[0], 'fstype': fields[2], 'options': fields[3] } mount_info.update(mount_statvfs_info) mount_facts['mounts'].append(mount_info) return mount_facts
def get_mount_facts(self): mount_facts = {} mount_facts['mounts'] = [] # For a detailed format description see mnttab(4) # special mount_point fstype options time fstab = get_file_content('/etc/mnttab') if fstab: for line in fstab.splitlines(): fields = line.split('\t') mount_statvfs_info = get_mount_size(fields[1]) mount_info = { 'mount': fields[1], 'device': fields[0], 'fstype': fields[2], 'options': fields[3], 'time': fields[4] } mount_info.update(mount_statvfs_info) mount_facts['mounts'].append(mount_info) return mount_facts
def main(): module = AssibleModule(argument_spec=dict( test=dict(type='str', default='strip'), touch_file=dict(type='str', default='/dev/null'), line_sep_file=dict(type='str', default='/dev/null'), line_sep_sep=dict(type='str', default='\n'), )) test = module.params['test'] facts = {} if test == 'strip': etc_passwd = get_file_content('/etc/passwd') etc_passwd_unstripped = get_file_content('/etc/passwd', strip=False) facts['etc_passwd_newlines'] = etc_passwd.count('\n') facts['etc_passwd_newlines_unstripped'] = etc_passwd_unstripped.count( '\n') elif test == 'default': path = module.params['touch_file'] facts['touch_default'] = get_file_content(path, default='i am a default') elif test == 'line_sep': path = module.params['line_sep_file'] sep = module.params['line_sep_sep'] facts['line_sep'] = get_file_lines(path, line_sep=sep) elif test == 'invalid_mountpoint': facts['invalid_mountpoint'] = get_mount_size('/doesnotexist') result = { 'changed': False, 'assible_facts': facts, } module.exit_json(**result)
def test_oserror_on_statvfs(self, mock_statvfs): mount_info = utils.get_mount_size('/dev/null/doesnt/matter') self.assertIsInstance(mount_info, dict) self.assertDictEqual(mount_info, {})
def test_proc(self): mount_info = utils.get_mount_size('/proc') self.assertIsInstance(mount_info, dict)
def test(self): mount_info = utils.get_mount_size('/dev/null/not/a/real/mountpoint') self.assertIsInstance(mount_info, dict)