diff --git a/changelogs/fragments/vyos_facts_update.yaml b/changelogs/fragments/vyos_facts_update.yaml new file mode 100644 index 0000000..8667aa0 --- /dev/null +++ b/changelogs/fragments/vyos_facts_update.yaml @@ -0,0 +1,3 @@ +--- +major_changes: + - "`vyos_facts` - change default gather_subset to `min` from `!config` (https://github.com/ansible-collections/vyos.vyos/issues/231)." diff --git a/docs/vyos.vyos.vyos_facts_module.rst b/docs/vyos.vyos.vyos_facts_module.rst index 83606d0..7e7d762 100644 --- a/docs/vyos.vyos.vyos_facts_module.rst +++ b/docs/vyos.vyos.vyos_facts_module.rst @@ -1,446 +1,446 @@ .. _vyos.vyos.vyos_facts_module: ******************** vyos.vyos.vyos_facts ******************** **Get facts about vyos devices.** Version added: 1.0.0 .. contents:: :local: :depth: 1 Synopsis -------- - Collects facts from network devices running the vyos operating system. This module places the facts gathered in the fact tree keyed by the respective resource name. The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts. Parameters ---------- .. raw:: html
Parameter Choices/Defaults Comments
available_network_resources
boolean
    Choices:
  • no ←
  • yes
When 'True' a list of network resources for which resource modules are available will be provided.
gather_network_resources
list / elements=string
When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all and the resources like interfaces. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected. Valid subsets are 'all', 'interfaces', 'l3_interfaces', 'lag_interfaces', 'lldp_global', 'lldp_interfaces', 'static_routes', 'firewall_rules', 'firewall_global', 'firewall_interfaces', 'ospfv3', 'ospfv2'.
gather_subset
list / elements=string
- Default:
"!config"
+ Default:
"min"
-
When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all, default, config, and neighbors. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected.
+
When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all, default, config, neighbors and min. Can specify a list of values to include a larger subset. Values can also be used with an initial ! to specify that a specific subset should not be collected.
provider
dictionary
Deprecated
Starting with Ansible 2.5 we recommend using connection: network_cli.
For more information please see the Network Guide.

A dict object containing connection details.
host
string
Specifies the DNS host name or address for connecting to the remote device over the specified transport. The value of host is used as the destination address for the transport.
password
string
Specifies the password to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_PASSWORD will be used instead.
port
integer
Specifies the port to use when building the connection to the remote device.
ssh_keyfile
path
Specifies the SSH key to use to authenticate the connection to the remote device. This value is the path to the key used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_SSH_KEYFILE will be used instead.
timeout
integer
Specifies the timeout in seconds for communicating with the network device for either connecting or sending commands. If the timeout is exceeded before the operation is completed, the module will error.
username
string
Configures the username to use to authenticate the connection to the remote device. This value is used to authenticate the SSH session. If the value is not specified in the task, the value of environment variable ANSIBLE_NET_USERNAME will be used instead.

Notes ----- .. note:: - Tested against VyOS 1.1.8 (helium). - This module works with connection ``network_cli``. See `the VyOS OS Platform Options <../network/user_guide/platform_vyos.html>`_. - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide ` Examples -------- .. code-block:: yaml # Gather all facts - vyos.vyos.vyos_facts: gather_subset: all gather_network_resources: all # collect only the config and default facts - vyos.vyos.vyos_facts: gather_subset: config # collect everything exception the config - vyos.vyos.vyos_facts: gather_subset: '!config' # Collect only the interfaces facts - vyos.vyos.vyos_facts: gather_subset: - '!all' - '!min' gather_network_resources: - interfaces # Do not collect interfaces facts - vyos.vyos.vyos_facts: gather_network_resources: - '!interfaces' # Collect interfaces and minimal default facts - vyos.vyos.vyos_facts: gather_subset: min gather_network_resources: interfaces Return Values ------------- Common return values are documented `here `_, the following are the fields unique to this module: .. raw:: html
Key Returned Description
ansible_net_api
string
always
The name of the transport

ansible_net_commits
list
when present
The set of available configuration revisions

ansible_net_config
string
when config is configured
The running-config from the device

ansible_net_gather_network_resources
list
always
The list of fact resource subsets collected from the device

ansible_net_gather_subset
list
always
The list of subsets gathered by the module

ansible_net_hostname
string
always
The configured system hostname

ansible_net_model
string
always
The device model string

ansible_net_neighbors
list
when interface is configured
The set of LLDP neighbors

ansible_net_python_version
string
always
The Python version Ansible controller is using

ansible_net_serialnum
string
always
The serial number of the device

ansible_net_version
string
always
The version of the software running



Status ------ Authors ~~~~~~~ - Nathaniel Case (@qalthos) - Nilashish Chakraborty (@Nilashishc) - Rohit Thakur (@rohitthakur2590) diff --git a/plugins/module_utils/network/vyos/argspec/facts/facts.py b/plugins/module_utils/network/vyos/argspec/facts/facts.py index efd98e3..45a4cb4 100644 --- a/plugins/module_utils/network/vyos/argspec/facts/facts.py +++ b/plugins/module_utils/network/vyos/argspec/facts/facts.py @@ -1,24 +1,22 @@ # Copyright 2019 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) """ The arg spec for the vyos facts module. """ from __future__ import absolute_import, division, print_function __metaclass__ = type class FactsArgs(object): # pylint: disable=R0903 """The arg spec for the vyos facts module""" def __init__(self, **kwargs): pass argument_spec = { - "gather_subset": dict( - default=["!config"], type="list", elements="str" - ), + "gather_subset": dict(default=["min"], type="list", elements="str"), "gather_network_resources": dict(type="list", elements="str"), "available_network_resources": {"type": "bool", "default": False}, } diff --git a/plugins/modules/vyos_facts.py b/plugins/modules/vyos_facts.py index ef19ec0..951dbe9 100644 --- a/plugins/modules/vyos_facts.py +++ b/plugins/modules/vyos_facts.py @@ -1,187 +1,187 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 2019 Red Hat # GNU General Public License v3.0+ # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type """ The module file for vyos_facts """ DOCUMENTATION = """ module: vyos_facts short_description: Get facts about vyos devices. description: - Collects facts from network devices running the vyos operating system. This module places the facts gathered in the fact tree keyed by the respective resource name. The facts module will always collect a base set of facts from the device and can enable or disable collection of additional facts. version_added: 1.0.0 author: - Nathaniel Case (@qalthos) - Nilashish Chakraborty (@Nilashishc) - Rohit Thakur (@rohitthakur2590) extends_documentation_fragment: - vyos.vyos.vyos notes: - Tested against VyOS 1.1.8 (helium). - This module works with connection C(network_cli). See L(the VyOS OS Platform Options,../network/user_guide/platform_vyos.html). options: gather_subset: description: - When supplied, this argument will restrict the facts collected to a given subset. Possible - values for this argument include all, default, config, and neighbors. Can specify + values for this argument include C(all), C(default), C(config), C(neighbors) and C(min). Can specify a list of values to include a larger subset. Values can also be used with an initial C(!) to specify that a specific subset should not be collected. required: false - default: '!config' + default: 'min' type: list elements: str gather_network_resources: description: - When supplied, this argument will restrict the facts collected to a given subset. Possible values for this argument include all and the resources like interfaces. Can specify a list of values to include a larger subset. Values can also be used with an initial C(!) to specify that a specific subset should not be collected. Valid subsets are 'all', 'interfaces', 'l3_interfaces', 'lag_interfaces', 'lldp_global', 'lldp_interfaces', 'static_routes', 'firewall_rules', 'firewall_global', 'firewall_interfaces', 'ospfv3', 'ospfv2'. required: false type: list elements: str available_network_resources: description: When 'True' a list of network resources for which resource modules are available will be provided. type: bool default: false """ EXAMPLES = """ # Gather all facts - vyos.vyos.vyos_facts: gather_subset: all gather_network_resources: all # collect only the config and default facts - vyos.vyos.vyos_facts: gather_subset: config # collect everything exception the config - vyos.vyos.vyos_facts: gather_subset: '!config' # Collect only the interfaces facts - vyos.vyos.vyos_facts: gather_subset: - '!all' - '!min' gather_network_resources: - interfaces # Do not collect interfaces facts - vyos.vyos.vyos_facts: gather_network_resources: - '!interfaces' # Collect interfaces and minimal default facts - vyos.vyos.vyos_facts: gather_subset: min gather_network_resources: interfaces """ RETURN = """ ansible_net_config: description: The running-config from the device returned: when config is configured type: str ansible_net_commits: description: The set of available configuration revisions returned: when present type: list ansible_net_hostname: description: The configured system hostname returned: always type: str ansible_net_model: description: The device model string returned: always type: str ansible_net_serialnum: description: The serial number of the device returned: always type: str ansible_net_version: description: The version of the software running returned: always type: str ansible_net_neighbors: description: The set of LLDP neighbors returned: when interface is configured type: list ansible_net_gather_subset: description: The list of subsets gathered by the module returned: always type: list ansible_net_api: description: The name of the transport returned: always type: str ansible_net_python_version: description: The Python version Ansible controller is using returned: always type: str ansible_net_gather_network_resources: description: The list of fact resource subsets collected from the device returned: always type: list """ from ansible.module_utils.basic import AnsibleModule from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.facts.facts import ( FactsArgs, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import ( Facts, FACT_RESOURCE_SUBSETS, ) from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( vyos_argument_spec, ) def main(): """ Main entry point for module execution :returns: ansible_facts """ argument_spec = FactsArgs.argument_spec argument_spec.update(vyos_argument_spec) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True ) warnings = [] if module.params["gather_subset"] == "!config": warnings.append( "default value for `gather_subset` will be changed to `min` from `!config` v2.11 onwards" ) ansible_facts = {} if module.params.get("available_network_resources"): ansible_facts["available_network_resources"] = sorted( FACT_RESOURCE_SUBSETS.keys() ) result = Facts(module).get_facts() additional_facts, additional_warnings = result ansible_facts.update(additional_facts) warnings.extend(additional_warnings) module.exit_json(ansible_facts=ansible_facts, warnings=warnings) if __name__ == "__main__": main() diff --git a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml index ede7ca2..a7c3a11 100644 --- a/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml +++ b/tests/integration/targets/vyos_facts/tests/cli/basic_facts.yaml @@ -1,55 +1,72 @@ --- - name: get host name register: vyos_host vyos.vyos.vyos_command: commands: - show host name - name: get version info register: vyos_version vyos.vyos.vyos_command: commands: - show version - name: collect all facts from the device register: result vyos.vyos.vyos_facts: gather_subset: all - name: check that hostname is present assert: that: - result.ansible_facts.ansible_net_hostname == vyos_host.stdout[0] - name: check that subsets are present assert: that: - "'neighbors' in result.ansible_facts.ansible_net_gather_subset" - "'default' in result.ansible_facts.ansible_net_gather_subset" - "'config' in result.ansible_facts.ansible_net_gather_subset" - name: check that version info is present assert: that: - result.ansible_facts.ansible_net_version in vyos_version.stdout_lines[0][0] - result.ansible_facts.ansible_net_model in vyos_version.stdout_lines[0][9] - result.ansible_facts.ansible_net_serialnum in vyos_version.stdout_lines[0][10] - name: check that config info is present assert: that: - result.ansible_facts.ansible_net_commits is defined - result.ansible_facts.ansible_net_config is defined - name: Get list of avaliable network resources for VyOS register: result vyos.vyos.vyos_facts: available_network_resources: true gather_network_resources: all - name: Assert that correct available_resources_list returned assert: that: - result.changed == false - "{{ result['ansible_facts']['available_network_resources'] | symmetric_difference(result['ansible_facts']['ansible_net_gather_network_resources']) |length\ \ == 0 }}" + +- name: test getting default facts + register: result + vyos.vyos.vyos_facts: + +- assert: + that: + - result.changed == false + - "'default' in result.ansible_facts.ansible_net_gather_subset" + - "'config' not in result.ansible_facts.ansible_net_gather_subset" + - result.ansible_facts.ansible_net_hostname is defined + - result.ansible_facts.ansible_net_model is defined + - result.ansible_facts.ansible_net_python_version is defined + - result.ansible_facts.ansible_net_serialnum is defined + - result.ansible_facts.ansible_net_system is defined + - result.ansible_facts.ansible_net_version is defined + - result.ansible_facts.ansible_network_resources == {}