From d80e78a9ae6ba1df503f49ab8836fae829acf34f Mon Sep 17 00:00:00 2001 From: Michel Blanc Date: Thu, 21 Feb 2013 01:10:25 +0100 Subject: [PATCH] Moved key filtering Key filtering moved before returning results --- setup | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/setup b/setup index 4dddd4384a1..b6c67fb1723 100644 --- a/setup +++ b/setup @@ -1102,12 +1102,9 @@ def run_setup(module): setup_options = {} facts = ansible_facts() - filtr = module.params['filter'] for (k, v) in facts.items(): - k2 = "ansible_%s" % k.replace('-', '_') - if fnmatch.fnmatch(k2, filtr): - setup_options[k2] = v + setup_options["ansible_%s" % k.replace('-', '_')] = v # if facter is installed, and we can use --json because # ruby-json is ALSO installed, include facter data in the JSON @@ -1121,9 +1118,7 @@ def run_setup(module): facter = False if facter: for (k,v) in facter_ds.items(): - k2 = "facter_%s" % k - if fnmatch.fnmatch(k2, filtr): - setup_options[k2] = v + setup_options["facter_%s" % k] = v # ditto for ohai, but just top level string keys # because it contains a lot of nested stuff we can't use for @@ -1140,11 +1135,13 @@ def run_setup(module): for (k,v) in ohai_ds.items(): if type(v) == str or type(v) == unicode: k2 = "ohai_%s" % k.replace('-', '_') - if fnmatch.fnmatch(k2, filtr): - setup_options[k2] = v + setup_options[k2] = v + + setup_result = { 'ansible_facts': {} } - setup_result = {} - setup_result['ansible_facts'] = setup_options + for (k,v) in setup_options.items(): + if fnmatch.fnmatch(k, module.params['filter']): + setup_result['ansible_facts'][k] = v # hack to keep --verbose from showing all the setup module results setup_result['verbose_override'] = True