summaryrefslogtreecommitdiff
path: root/lib/ansible/modules
diff options
context:
space:
mode:
authorBrian Coca <bcoca@users.noreply.github.com>2021-04-05 02:34:26 -0400
committerGitHub <noreply@github.com>2021-04-05 01:34:26 -0500
commit7683dfb7278afa24ee0d6d53968110b8bd467641 (patch)
tree39e6a5a2ff8ed48406eff31de74b02b0a84e0911 /lib/ansible/modules
parentadae63e053fae822b26beb2fa9b70b7ba2da34b1 (diff)
downloadansible-7683dfb7278afa24ee0d6d53968110b8bd467641.tar.gz
Fix setup subset (#74022) (#74047)
* fix error msg on bad subset * added test * handle more raised but not handled fact exceptions (cherry picked from commit 4a82e2c4860b88aa2d5ab2fd1f7cd79636005b5f) * Update fix_setup_bad_subset.yml Co-authored-by: Rick Elrod <rick@elrod.me>
Diffstat (limited to 'lib/ansible/modules')
-rw-r--r--lib/ansible/modules/setup.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/ansible/modules/setup.py b/lib/ansible/modules/setup.py
index f2040dfc34..520b947196 100644
--- a/lib/ansible/modules/setup.py
+++ b/lib/ansible/modules/setup.py
@@ -126,10 +126,10 @@ EXAMPLES = """
# import module snippets
from ..module_utils.basic import AnsibleModule
+from ansible.module_utils._text import to_text
+from ansible.module_utils.facts import ansible_collector, default_collectors
+from ansible.module_utils.facts.collector import CollectorNotFoundError, CycleFoundInFactDeps, UnresolvedFactDep
from ansible.module_utils.facts.namespace import PrefixFactNamespace
-from ansible.module_utils.facts import ansible_collector
-
-from ansible.module_utils.facts import default_collectors
def main():
@@ -162,13 +162,16 @@ def main():
namespace = PrefixFactNamespace(namespace_name='ansible',
prefix='ansible_')
- fact_collector = \
- ansible_collector.get_ansible_collector(all_collector_classes=all_collector_classes,
- namespace=namespace,
- filter_spec=filter_spec,
- gather_subset=gather_subset,
- gather_timeout=gather_timeout,
- minimal_gather_subset=minimal_gather_subset)
+ try:
+ fact_collector = ansible_collector.get_ansible_collector(all_collector_classes=all_collector_classes,
+ namespace=namespace,
+ filter_spec=filter_spec,
+ gather_subset=gather_subset,
+ gather_timeout=gather_timeout,
+ minimal_gather_subset=minimal_gather_subset)
+ except (TypeError, CollectorNotFoundError, CycleFoundInFactDeps, UnresolvedFactDep) as e:
+ # bad subset given, collector, idk, deps declared but not found
+ module.fail_json(msg=to_text(e))
facts_dict = fact_collector.collect(module=module)