Workaround python-libselinux API change (#25685)

In the past, selinux.security_get_boolean_names did return 'bytes'
on python 3, but this was changed to return string later, cf:
b8711e2eaf

So we have to convert to bytes only if the API return us bytes.

Fix #25651
(cherry picked from commit e2d6ecfa40)
pull/27315/head
Michael Scherer 7 years ago committed by Toshio Kuratomi
parent 0a7bad68dc
commit 1628a25d8d

@ -79,7 +79,12 @@ def has_boolean_value(module, name):
rc, bools = selinux.security_get_boolean_names() rc, bools = selinux.security_get_boolean_names()
except OSError: except OSError:
module.fail_json(msg="Failed to get list of boolean names") module.fail_json(msg="Failed to get list of boolean names")
if to_bytes(name) in bools: # work around for selinux who changed its API, see
# https://github.com/ansible/ansible/issues/25651
if len(bools) > 0:
if isinstance(bools[0], binary_type):
name = to_bytes(name)
if name in bools:
return True return True
else: else:
return False return False
@ -224,6 +229,7 @@ def main():
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_bytes
from ansible.module_utils.six import binary_type
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save