diff --git a/changelogs/fragments/5615-zypper-transactional-update.yml b/changelogs/fragments/5615-zypper-transactional-update.yml new file mode 100644 index 0000000000..5eb6bb8405 --- /dev/null +++ b/changelogs/fragments/5615-zypper-transactional-update.yml @@ -0,0 +1,2 @@ +bugfixes: + - "zypper - make package managing work on readonly filesystem of openSUSE MicroOS (https://github.com/ansible-collections/community.general/pull/5615)." diff --git a/plugins/modules/zypper.py b/plugins/modules/zypper.py index 775ff0fd6e..9ba5555e20 100644 --- a/plugins/modules/zypper.py +++ b/plugins/modules/zypper.py @@ -519,8 +519,21 @@ def repo_refresh(m): return retvals +def get_fs_type_and_readonly_state(mount_point): + with open('/proc/mounts', 'r') as file: + for line in file.readlines(): + fields = line.split() + path = fields[1] + if path == mount_point: + fs = fields[2] + opts = fields[3] + return fs, 'ro' in opts.split(',') + return None + + def transactional_updates(): - return os.path.exists('/var/lib/misc/transactional-update.state') + return os.path.exists('/usr/sbin/transactional-update') and get_fs_type_and_readonly_state('/') == ('btrfs', True) + # =========================================== # Main control flow