add a 'min' type for gather_subset to collect nothing (#27085)

previously gather_subset=['!all'] would still gather the
min set of facts, and there was no way to collect no facts.

The 'min' specifier in gather_subset is equilivent to
exclude the minimal_gather_subset facts as well.

   gather_subset=['!all', '!min'] will collect no facts

This also lets explicitly added gather_subsets override excludes.

   gather_subset=['pkg_mgr', '!all', '!min'] will collect only the pkg_mgr
fact.
This commit is contained in:
Adrian Likins 2017-08-02 11:04:01 -04:00 committed by GitHub
commit 27a015f0ad
4 changed files with 172 additions and 36 deletions

View file

@ -1,5 +1,4 @@
---
- hosts: facthost7
tags: [ 'fact_negation' ]
connection: local
@ -12,9 +11,6 @@
- "!hardware"
register: not_hardware_facts
- name: debug setup with not hardware
debug:
var: not_hardware_facts
- hosts: facthost0
tags: [ 'fact_min' ]
@ -67,6 +63,7 @@
- 'ansible_mounts|default("UNDEF_MOUNT") == "UNDEF_MOUNT"'
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
- 'ansible_env|default("UNDEF_ENV") == "UNDEF_ENV"'
- 'ansible_pkg_mgr|default("UNDEF_PKG_MGR") == "UNDEF_PKG_MGR"'
- hosts: facthost11
tags: [ 'fact_min' ]
@ -111,7 +108,10 @@
- name: Test that only retrieving minimal facts work
assert:
that:
# from the min set, which should still collect
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"'
- 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"'
# non min facts that are not collected
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"'
- 'ansible_mounts|default("UNDEF_HW") == "UNDEF_HW"'
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
@ -198,10 +198,16 @@
- name: Test that negation of fact subsets work
assert:
that:
# network, not collected since it is not in min
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"'
# not collecting virt, should be undef
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
# mounts/devices are collected by hardware, so should be not collected and undef
- 'ansible_mounts|default("UNDEF_MOUNTS") == "UNDEF_MOUNTS"'
- 'ansible_devices|default("UNDEF_DEVICES") == "UNDEF_DEVICES"'
# from the min set, which should still collect
- 'ansible_user_id|default("UNDEF_MIN") != "UNDEF_MIN"'
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"'
- 'ansible_mounts|default("UNDEF_HW") == "UNDEF_HW"'
- 'ansible_virtualization_role|default("UNDEF_VIRT") != "UNDEF_VIRT"'
- 'ansible_env|default("UNDEF_ENV") != "UNDEF_ENV"'
- hosts: facthost8
tags: [ 'fact_mixed_negation_addition' ]
@ -217,6 +223,46 @@
- 'ansible_mounts|default("UNDEF_HW") == "UNDEF_HW"'
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
- hosts: facthost14
tags: [ 'fact_mixed_negation_addition_min' ]
connection: local
gather_subset: "!all,!min,network"
gather_facts: yes
tasks:
- name: Test that negation and additional subsets work together for min subset
assert:
that:
- 'ansible_user_id|default("UNDEF_MIN") == "UNDEF_MIN"'
- 'ansible_interfaces|default("UNDEF_NET") != "UNDEF_NET"'
- 'ansible_default_ipv4|default("UNDEF_DEFAULT_IPV4") != "UNDEF_DEFAULT_IPV4"'
- 'ansible_all_ipv4_addresses|default("UNDEF_ALL_IPV4") != "UNDEF_ALL_IPV4"'
- 'ansible_mounts|default("UNDEF_HW") == "UNDEF_HW"'
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
- 'ansible_env|default("UNDEF_ENV") == "UNDEF_ENV"'
- hosts: facthost15
tags: [ 'fact_negate_all_min_add_pkg_mgr' ]
connection: local
gather_subset: "!all,!min,pkg_mgr"
gather_facts: yes
tasks:
- name: Test that negation and additional subsets work together for min subset
assert:
that:
# network, not collected since it is not in min
- 'ansible_interfaces|default("UNDEF_NET") == "UNDEF_NET"'
# not collecting virt, should be undef
- 'ansible_virtualization_role|default("UNDEF_VIRT") == "UNDEF_VIRT"'
# mounts/devices are collected by hardware, so should be not collected and undef
- 'ansible_mounts|default("UNDEF_MOUNTS") == "UNDEF_MOUNTS"'
- 'ansible_devices|default("UNDEF_DEVICES") == "UNDEF_DEVICES"'
# from the min set, which should not collect
- 'ansible_user_id|default("UNDEF_MIN") == "UNDEF_MIN"'
- 'ansible_env|default("UNDEF_ENV") == "UNDEF_ENV"'
# the pkg_mgr fact we requested explicitly
- 'ansible_pkg_mgr|default("UNDEF_PKG_MGR") != "UNDEF_PKGMGR"'
- hosts: facthost9
tags: [ 'fact_local']
connection: local