diff --git a/changelogs/fragments/setup_filter_smarter.yml b/changelogs/fragments/setup_filter_smarter.yml new file mode 100644 index 00000000000..04fbffc238e --- /dev/null +++ b/changelogs/fragments/setup_filter_smarter.yml @@ -0,0 +1,2 @@ +bugfixes: + - setup module, fix filter to adjust for missing ``ansible_`` prefix on query. diff --git a/changelogs/fragments/ssh_conn_fixes.yml b/changelogs/fragments/ssh_conn_fixes.yml new file mode 100644 index 00000000000..978792b7d0f --- /dev/null +++ b/changelogs/fragments/ssh_conn_fixes.yml @@ -0,0 +1,4 @@ +bugfixes: + - ssh connection now correctly handle ssh_transfer_method and scp_if_ssh interactions. +minor_changes: + - ssh connection, ssh_transfer_method is now configurable via variable. diff --git a/lib/ansible/module_utils/facts/ansible_collector.py b/lib/ansible/module_utils/facts/ansible_collector.py index 7f6f576f9c2..f8238afe314 100644 --- a/lib/ansible/module_utils/facts/ansible_collector.py +++ b/lib/ansible/module_utils/facts/ansible_collector.py @@ -61,7 +61,17 @@ class AnsibleFactCollector(collector.BaseFactCollector): if is_string(filter_spec): filter_spec = [filter_spec] - return [(x, y) for x, y in facts_dict.items() for f in filter_spec if not f or fnmatch.fnmatch(x, f)] + found = [] + for f in filter_spec: + for x, y in facts_dict.items(): + if not f or fnmatch.fnmatch(x, f): + found.append((x, y)) + elif not f.startswith(('ansible_', 'facter', 'ohai')): + # try to match with ansible_ prefix added when non empty + g = 'ansible_%s' % f + if fnmatch.fnmatch(x, g): + found.append((x, y)) + return found def collect(self, module=None, collected_facts=None): collected_facts = collected_facts or {} diff --git a/test/integration/targets/gathering_facts/inventory b/test/integration/targets/gathering_facts/inventory index e15ae780f0a..6352a7d7e13 100644 --- a/test/integration/targets/gathering_facts/inventory +++ b/test/integration/targets/gathering_facts/inventory @@ -1,2 +1,2 @@ [local] -facthost[0:25] ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}" +facthost[0:26] ansible_connection=local ansible_python_interpreter="{{ ansible_playbook_python }}" diff --git a/test/integration/targets/gathering_facts/test_gathering_facts.yml b/test/integration/targets/gathering_facts/test_gathering_facts.yml index 0939cba702a..9174675d44e 100644 --- a/test/integration/targets/gathering_facts/test_gathering_facts.yml +++ b/test/integration/targets/gathering_facts/test_gathering_facts.yml @@ -140,6 +140,34 @@ - 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"' - 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"' +- hosts: facthost25 + tags: [ 'fact_min' ] + gather_facts: no + tasks: + - setup: + filter: + - "date_time" + + - name: Test that retrieving all facts filtered to date_time even w/o using ansible_ prefix + assert: + that: + - 'ansible_facts["date_time"]|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' + - 'ansible_date_time|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' + +- hosts: facthost26 + tags: [ 'fact_min' ] + gather_facts: no + tasks: + - setup: + filter: + - "ansible_date_time" + + - name: Test that retrieving all facts filtered to date_time even using ansible_ prefix + assert: + that: + - 'ansible_facts["date_time"]|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' + - 'ansible_date_time|default("UNDEF_MOUNT") != "UNDEF_MOUNT"' + - hosts: facthost13 tags: [ 'fact_min' ] connection: local