* fix error msg on bad subset
* added test
* handle more raised but not handled fact exceptions
| ... | ... |
@@ -144,10 +144,10 @@ EXAMPLES = """ |
| 144 | 144 |
# import module snippets |
| 145 | 145 |
from ..module_utils.basic import AnsibleModule |
| 146 | 146 |
|
| 147 |
+from ansible.module_utils._text import to_text |
|
| 148 |
+from ansible.module_utils.facts import ansible_collector, default_collectors |
|
| 149 |
+from ansible.module_utils.facts.collector import CollectorNotFoundError, CycleFoundInFactDeps, UnresolvedFactDep |
|
| 147 | 150 |
from ansible.module_utils.facts.namespace import PrefixFactNamespace |
| 148 |
-from ansible.module_utils.facts import ansible_collector |
|
| 149 |
- |
|
| 150 |
-from ansible.module_utils.facts import default_collectors |
|
| 151 | 151 |
|
| 152 | 152 |
|
| 153 | 153 |
def main(): |
| ... | ... |
@@ -180,13 +180,16 @@ def main(): |
| 180 | 180 |
namespace = PrefixFactNamespace(namespace_name='ansible', |
| 181 | 181 |
prefix='ansible_') |
| 182 | 182 |
|
| 183 |
- fact_collector = \ |
|
| 184 |
- ansible_collector.get_ansible_collector(all_collector_classes=all_collector_classes, |
|
| 185 |
- namespace=namespace, |
|
| 186 |
- filter_spec=filter_spec, |
|
| 187 |
- gather_subset=gather_subset, |
|
| 188 |
- gather_timeout=gather_timeout, |
|
| 189 |
- minimal_gather_subset=minimal_gather_subset) |
|
| 183 |
+ try: |
|
| 184 |
+ fact_collector = ansible_collector.get_ansible_collector(all_collector_classes=all_collector_classes, |
|
| 185 |
+ namespace=namespace, |
|
| 186 |
+ filter_spec=filter_spec, |
|
| 187 |
+ gather_subset=gather_subset, |
|
| 188 |
+ gather_timeout=gather_timeout, |
|
| 189 |
+ minimal_gather_subset=minimal_gather_subset) |
|
| 190 |
+ except (TypeError, CollectorNotFoundError, CycleFoundInFactDeps, UnresolvedFactDep) as e: |
|
| 191 |
+ # bad subset given, collector, idk, deps declared but not found |
|
| 192 |
+ module.fail_json(msg=to_text(e)) |
|
| 190 | 193 |
|
| 191 | 194 |
facts_dict = fact_collector.collect(module=module) |
| 192 | 195 |
|
| ... | ... |
@@ -16,3 +16,6 @@ ansible-playbook verify_merge_facts.yml -v "$@" -e 'ansible_facts_parallel: Fals |
| 16 | 16 |
|
| 17 | 17 |
# ensure we dont clobber facts in loop |
| 18 | 18 |
ansible-playbook prevent_clobbering.yml -v "$@" |
| 19 |
+ |
|
| 20 |
+# ensure we dont fail module on bad subset |
|
| 21 |
+ansible-playbook verify_subset.yml "$@" |
| 19 | 22 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,13 @@ |
| 0 |
+- hosts: localhost |
|
| 1 |
+ gather_facts: false |
|
| 2 |
+ tasks: |
|
| 3 |
+ - name: bad subset used |
|
| 4 |
+ setup: gather_subset=nonsense |
|
| 5 |
+ register: bad_sub |
|
| 6 |
+ ignore_errors: true |
|
| 7 |
+ |
|
| 8 |
+ - name: verify we fail the right way |
|
| 9 |
+ assert: |
|
| 10 |
+ that: |
|
| 11 |
+ - bad_sub is failed |
|
| 12 |
+ - "'MODULE FAILURE' not in bad_sub['msg']" |