setup module, filter compensate for prefixes (#74924)
Allow user to abstract internal implementation from requested info
This commit is contained in:
parent
cf3a304ce1
commit
d2d45900ed
5 changed files with 46 additions and 2 deletions
2
changelogs/fragments/setup_filter_smarter.yml
Normal file
2
changelogs/fragments/setup_filter_smarter.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- setup module, fix filter to adjust for missing ``ansible_`` prefix on query.
|
4
changelogs/fragments/ssh_conn_fixes.yml
Normal file
4
changelogs/fragments/ssh_conn_fixes.yml
Normal file
|
@ -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.
|
|
@ -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 {}
|
||||
|
|
|
@ -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 }}"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue