How to identify the device on which the file or directory resides?
There is a stat module.
Among the results there is a "Device the inode resides on".
How can you map the "Device the inode resides on" to a partition?
How to identify the device on which the file or directory resides?
There is a stat module.
Among the results there is a "Device the inode resides on".
How can you map the "Device the inode resides on" to a partition?
First one need to understand What is the device of inode? and device number in
stat
command output.Then, for an example debug output
there is a Device ID with
2051
decimal but we would need it in HEX. According How can I convert a decimal string to an hexadecimal string? a task likewould report
This needs to be split into major (
8
) and minor (3
) device. Maybe start withIn an other task it would be necessary to gather the result of
and parse it accordingly since
ansible_facts.device_links
ansible_facts.devices
do not collect and hold that kind of information.Depending on the infrastructure
lsblk --output
formatted for necessary information only might be easier.Or according How to get a device/partition name of a file? just
From here we can see Major 8 (SCSI) and Minor 3 is
/dev/sda3
. And "How to find out what's behind the major number?", see in example Linux : Major and Minor device numbers or Major and minor numbers of a partition.An example task with zero padded fields from text file
will result into an output of
The numbers are accessible as well transformable into integer in example as follow
resulting into an output of
Finally, a task
will report
supplement: for a minor number must take the last two digits of the number
File:
/path/to/file1
linux stat:
device 8/1
ansible device stat:
dev: 2049
2049 (DEC) = 801 (HEX) -->
8
.01
-->8
/01
(HEX) =8
/1
(DEC)File:
/path/to/file2
linux stat:
device 259/2
ansible device stat:
dev: 66306
66306 (DEC) = 10302 (HEX) -->
103
.02
-->103
/02
(HEX) =259
/2
(DEC)File:
/path/to/file3
linux stat:
device 254/1
ansible device stat:
dev: 65025
65025 (DEC) = FE01 (HEX) -->
FE
.01
-->FE
/01
(HEX) =254
/1
(DEC)File:
/path/to/file4
linux stat:
device 0/45
ansible device stat:
dev: 45
45 (DEC) = 2D (HEX) -->
0
.2D
-->0
/2D
(HEX) =0
/45
(DEC)