diff --git a/lib/ansible/modules/packaging/os/rpm_key.py b/lib/ansible/modules/packaging/os/rpm_key.py index 74899fd311..73c7cc9670 100644 --- a/lib/ansible/modules/packaging/os/rpm_key.py +++ b/lib/ansible/modules/packaging/os/rpm_key.py @@ -75,12 +75,19 @@ import re import os.path import tempfile +# import module snippets +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.urls import fetch_url +from ansible.module_utils._text import to_native + + def is_pubkey(string): """Verifies if string is a pubkey""" pgp_regex = ".*?(-----BEGIN PGP PUBLIC KEY BLOCK-----.*?-----END PGP PUBLIC KEY BLOCK-----).*" - return re.match(pgp_regex, string, re.DOTALL) + return bool(re.match(pgp_regex, to_native(string, errors='surrogate_or_strict'), re.DOTALL)) -class RpmKey: + +class RpmKey(object): def __init__(self, module): # If the key is a url, we need to check if it's present to be idempotent, @@ -122,7 +129,6 @@ class RpmKey: else: module.exit_json(changed=False) - def fetch_key(self, url): """Downloads a key from url, returns a valid path to a gpg key""" rsp, info = fetch_url(self.module, url) @@ -212,9 +218,5 @@ def main(): RpmKey(module) - -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.urls import * if __name__ == '__main__': main()