diff --git a/lib/ansible/modules/system/setup.py b/lib/ansible/modules/system/setup.py index c3a927f45fd..3d064ae8b49 100644 --- a/lib/ansible/modules/system/setup.py +++ b/lib/ansible/modules/system/setup.py @@ -27,25 +27,16 @@ options: gather_subset: version_added: "2.1" description: - - if supplied, restrict facts collected at the given subset. - Here is the possible values: all, min, hardware, network or virtual - Can be combined using comma (ex: gather_subset=network,virtual). + - "if supplied, restrict the additional facts collected to the given subset. + Possible values: all, hardware, network, virtual, ohai, and + facter Can specify a list of values to specify a larger subset. + Values can also be used with an initial C(!) to specify that + that specific subset should not be collected. For instance: + !hardware, !network, !virtual, !ohai, !facter. Note that a few + facts are always collected. Use the filter parameter if you do + not want to display those." required: false default: 'all' - ignore_ohai: - version_added: "2.1" - description: - - if supplied, do not run ohai even if present - required: false - default: no - choices: [ yes, no ] - ignore_facter: - version_added: "2.1" - description: - - if supplied, do not run facter even if present - required: false - default: no - choices: [ yes, no ] filter: version_added: "1.1" description: @@ -102,90 +93,35 @@ ansible all -m setup -a 'filter=facter_*' # Display only facts about certain interfaces. ansible all -m setup -a 'filter=ansible_eth[0-2]' -# Restrict gathered facts to network and virtual. +# Restrict additional gathered facts to network and virtual. ansible all -m setup -a 'gather_subset=network,virtual' # Do not call puppet facter or ohai even if present. -ansible all -m setup -a 'ignore_facter=yes ignore_ohai=yes' +ansible all -m setup -a 'gather_subset=!facter,!ohai' + +# Only collect the minimum amount of facts: +ansible all -m setup -a 'gather_subset=!all' # Display facts from Windows hosts with custom facts stored in C(C:\\custom_facts). ansible windows -m setup -a "fact_path='c:\\custom_facts'" """ -def run_setup(module): - - setup_options = dict(module_setup=True) - facts = ansible_facts(module) - - for (k, v) in facts.items(): - setup_options["ansible_%s" % k.replace('-', '_')] = v - - # Look for the path to the facter and ohai binary and set - # the variable to that path. - facter_path = None - ohai_path = None - if not module.params['ignore_facter']: - facter_path = module.get_bin_path('facter', opt_dirs=['/opt/puppetlabs/bin']) - if not module.params['ignore_ohai']: - ohai_path = module.get_bin_path('ohai') - - # if facter is installed, and we can use --json because - # ruby-json is ALSO installed, include facter data in the JSON - if facter_path is not None: - rc, out, err = module.run_command(facter_path + " --puppet --json") - facter = True - try: - facter_ds = json.loads(out) - except: - facter = False - if facter: - for (k,v) in facter_ds.items(): - setup_options["facter_%s" % k] = v - - # ditto for ohai - if ohai_path is not None: - rc, out, err = module.run_command(ohai_path) - ohai = True - try: - ohai_ds = json.loads(out) - except: - ohai = False - if ohai: - for (k,v) in ohai_ds.items(): - k2 = "ohai_%s" % k.replace('-', '_') - setup_options[k2] = v - - setup_result = { 'ansible_facts': {} } - - for (k,v) in setup_options.items(): - if module.params['filter'] == '*' or 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['_ansible_verbose_override'] = True - - return setup_result - def main(): - global module module = AnsibleModule( argument_spec = dict( - gather_subset=dict(default="all", required=False, type='list'), - ignore_ohai=dict(default=False, required=False), - ignore_facter=dict(default=False, required=False), + gather_subset=dict(default=["all"], required=False, type='list'), filter=dict(default="*", required=False), fact_path=dict(default='/etc/ansible/facts.d', required=False), ), supports_check_mode = True, ) - data = run_setup(module) + data = get_all_facts(module) module.exit_json(**data) # import module snippets - from ansible.module_utils.basic import * - from ansible.module_utils.facts import * -main() +if __name__ == '__main__': + main()