Skip to content

Commit 2bac761

Browse files
committed
fix: ensure libblockdev-loop package on EL7 for loop mounts
Cause: The blivet module on EL7 will try to use a function that is undefined when checking for mounts if there is a loop mount (/dev/loopX) on the system. The function is provided by the libblockdev-loop package but that isn't always installed. Consequence: The role will give an error like: "The function 'bd_loop_get_backing_file' called, but not implemented" Fix: Ensure that the libblockdev-loop package is installed if there are loop mounts on the EL7 system. Result: The role works on EL7 when there are loop mounts. Added a test to create a loop mount. Signed-off-by: Rich Megginson <[email protected]>
1 parent 476acb8 commit 2bac761

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

tasks/main-blivet.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@
3939
when: storage_skip_checks is not defined or
4040
not "packages_installed" in storage_skip_checks
4141

42+
# There is a bug in blivet in EL7 where it will try to use a function defined
43+
# in libblockdev-loop that is not installed by default when there is a loop mount.
44+
# Ensure that the library is available in this case.
45+
- name: Ensure libblockdev-loop on EL7
46+
when:
47+
- ansible_facts['os_family'] == "RedHat"
48+
- ansible_facts['distribution_major_version'] == "7"
49+
- not "libblockdev-loop" in package_info.packages | d([])
50+
- ansible_facts["packages"] | d([]) | selectattr("name", "match", "^libblockdev-loop$") | list | length == 0
51+
block:
52+
- name: Refresh mount facts
53+
setup:
54+
gather_subset: ["!all", "!min", "mounts"]
55+
56+
- name: Ensure libblockdev-loop is installed if there are loop mounts
57+
package:
58+
name: libblockdev-loop
59+
state: present
60+
use: "{{ (__storage_is_ostree | d(false)) |
61+
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
62+
when: ansible_facts["mounts"] | selectattr("device", "match", "^/dev/loop") | list | length > 0
63+
4264
- name: Make sure required packages are installed
4365
package:
4466
name: "{{ package_info.packages + extra_pkgs }}"

tests/tests_change_disk_mount.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88
volume_size: '5g'
99

1010
tasks:
11+
- name: Create blockdev and loop mount
12+
shell: |
13+
set -euxo pipefail
14+
exec 1>&2
15+
dd if=/dev/zero of=/tmp/loop.img bs=1024 count=64
16+
mkfs.ext4 -v -F /tmp/loop.img
17+
mkdir /mnt/loop_test
18+
mount /tmp/loop.img /mnt/loop_test
19+
cat /proc/mounts | grep loop
20+
changed_when: false
21+
1122
- name: Run the role
1223
include_role:
1324
name: linux-system-roles.storage
@@ -79,3 +90,11 @@
7990

8091
- name: Verify role results - 4
8192
include_tasks: verify-role-results.yml
93+
94+
- name: Clean up loop mount
95+
shell: |
96+
set -euxo pipefail
97+
exec 1>&2
98+
umount /mnt/loop_test
99+
rm -rf /tmp/loop.img /mnt/loop_test
100+
changed_when: false

0 commit comments

Comments
 (0)