summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2016-03-14 15:05:20 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2016-03-14 15:05:20 -0700
commit7f6810d6bf84a9302e0eecc5d5973f2c25be39f7 (patch)
tree7af2af570a892142e271437b00bdff9d4d1543e6
parent4c14108b7ee1c977ca2f4b83bb6ce8d4be47841f (diff)
downloadansible-modules-core-facts-subset-and-cleanup.tar.gz
Remove the ignore_ohai and ignore_facter parameters as the functionality was merged into gather_subsetfacts-subset-and-cleanup
-rw-r--r--system/setup.py98
1 files changed, 17 insertions, 81 deletions
diff --git a/system/setup.py b/system/setup.py
index c3a927f4..3d064ae8 100644
--- a/system/setup.py
+++ b/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()