summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorYannig Perré <yannig.perre@gmail.com>2016-03-07 21:53:29 +0100
committerToshio Kuratomi <toshio@fedoraproject.org>2016-03-14 09:31:18 -0700
commitbaf8109dcceea7712d7cc5ff0fdb0f2ea94d79bb (patch)
tree535fa65dac38d0dc21fe0c8ed4d2618e526d96c5 /system
parenteef9c54874bda4846f3c2e8ef479b34c0f02e82e (diff)
downloadansible-modules-core-baf8109dcceea7712d7cc5ff0fdb0f2ea94d79bb.tar.gz
Add a way to restrict gathered facts in Ansible:
- Using gather_subset options - By ignoring ohai/chef or facter/puppet facts
Diffstat (limited to 'system')
-rw-r--r--system/setup.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/system/setup.py b/system/setup.py
index 8830e9d2..68f3f8b1 100644
--- a/system/setup.py
+++ b/system/setup.py
@@ -24,6 +24,28 @@ module: setup
version_added: historical
short_description: Gathers facts about remote hosts
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).
+ 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:
@@ -80,6 +102,12 @@ 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.
+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'
+
# Display facts from Windows hosts with custom facts stored in C(C:\\custom_facts).
ansible windows -m setup -a "fact_path='c:\\custom_facts'"
"""
@@ -95,8 +123,12 @@ def run_setup(module):
# Look for the path to the facter and ohai binary and set
# the variable to that path.
- facter_path = module.get_bin_path('facter', opt_dirs=['/opt/puppetlabs/bin'])
- ohai_path = module.get_bin_path('ohai')
+ 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
@@ -139,6 +171,9 @@ def main():
global module
module = AnsibleModule(
argument_spec = dict(
+ gather_subset=dict(default="all", required=False),
+ ignore_ohai=dict(default=False, required=False),
+ ignore_facter=dict(default=False, required=False),
filter=dict(default="*", required=False),
fact_path=dict(default='/etc/ansible/facts.d', required=False),
),