diff options
author | Matt Martz <matt@sivel.net> | 2022-04-05 15:28:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-05 15:28:56 -0500 |
commit | 85341c3e5de751cef4887b3d28b609e07e77b9e8 (patch) | |
tree | e1dd2b71fd46d5ce7012c9a29103bd7d70b49a78 | |
parent | ee9705a1ceb4dd80796f3b4c40de8c5c01ebc7e2 (diff) | |
download | ansible-85341c3e5de751cef4887b3d28b609e07e77b9e8.tar.gz |
[stable-2.13] Catch ImportError when pyyaml doesn't have libyaml extension (#77434) (#77459)
* [stable-2.13] Catch ImportError when pyyaml doesn't have libyaml extension (#77434)
(cherry picked from commit e3aa73c)
Co-authored-by: Matt Martz <matt@sivel.net>
* Add test to assert that missing libyaml doesn't result in an error. Fixes #77437
(cherry picked from commit 2797dc644aa8c809444ccac64cad63e0d9a3f9fe)
-rw-r--r-- | lib/ansible/module_utils/common/yaml.py | 2 | ||||
-rw-r--r-- | test/integration/targets/pyyaml/aliases | 2 | ||||
-rwxr-xr-x | test/integration/targets/pyyaml/runme.sh | 11 |
3 files changed, 14 insertions, 1 deletions
diff --git a/lib/ansible/module_utils/common/yaml.py b/lib/ansible/module_utils/common/yaml.py index f91bf1234d..e79cc09642 100644 --- a/lib/ansible/module_utils/common/yaml.py +++ b/lib/ansible/module_utils/common/yaml.py @@ -27,7 +27,7 @@ if HAS_YAML: from yaml.cyaml import CParser as Parser HAS_LIBYAML = True - except AttributeError: + except (ImportError, AttributeError): from yaml import SafeLoader # type: ignore[misc] from yaml import SafeDumper # type: ignore[misc] from yaml.parser import Parser # type: ignore[misc] diff --git a/test/integration/targets/pyyaml/aliases b/test/integration/targets/pyyaml/aliases new file mode 100644 index 0000000000..1d28bdb2aa --- /dev/null +++ b/test/integration/targets/pyyaml/aliases @@ -0,0 +1,2 @@ +shippable/posix/group5 +context/controller diff --git a/test/integration/targets/pyyaml/runme.sh b/test/integration/targets/pyyaml/runme.sh new file mode 100755 index 0000000000..0361835a0d --- /dev/null +++ b/test/integration/targets/pyyaml/runme.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -eu +source virtualenv.sh +set +x + +# deps are already installed, using --no-deps to avoid re-installing them +# Install PyYAML without libyaml to validate ansible can run +PYYAML_FORCE_LIBYAML=0 pip install --no-binary PyYAML --ignore-installed --no-cache-dir --no-deps PyYAML + +ansible --version | tee /dev/stderr | grep 'libyaml = False' |