Add a way to restrict gathered facts in Ansible:

- Using gather_subset options
- By ignoring ohai/chef or facter/puppet facts
reviewable/pr18780/r1
Yannig Perré 9 years ago committed by Toshio Kuratomi
parent eef9c54874
commit baf8109dcc

@ -24,6 +24,28 @@ module: setup
version_added: historical version_added: historical
short_description: Gathers facts about remote hosts short_description: Gathers facts about remote hosts
options: 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: filter:
version_added: "1.1" version_added: "1.1"
description: description:
@ -80,6 +102,12 @@ ansible all -m setup -a 'filter=facter_*'
# Display only facts about certain interfaces. # Display only facts about certain interfaces.
ansible all -m setup -a 'filter=ansible_eth[0-2]' 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). # Display facts from Windows hosts with custom facts stored in C(C:\\custom_facts).
ansible windows -m setup -a "fact_path='c:\\custom_facts'" ansible windows -m setup -a "fact_path='c:\\custom_facts'"
""" """
@ -95,7 +123,11 @@ def run_setup(module):
# Look for the path to the facter and ohai binary and set # Look for the path to the facter and ohai binary and set
# the variable to that path. # 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']) 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') ohai_path = module.get_bin_path('ohai')
# if facter is installed, and we can use --json because # if facter is installed, and we can use --json because
@ -139,6 +171,9 @@ def main():
global module global module
module = AnsibleModule( module = AnsibleModule(
argument_spec = dict( 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), filter=dict(default="*", required=False),
fact_path=dict(default='/etc/ansible/facts.d', required=False), fact_path=dict(default='/etc/ansible/facts.d', required=False),
), ),

Loading…
Cancel
Save