2016-09-17 17:35:29 +00:00
|
|
|
#!/usr/bin/python
|
2016-09-17 17:19:16 +00:00
|
|
|
#
|
2016-09-17 17:23:45 +00:00
|
|
|
# (c) 2015 Peter Sprygada, <psprygada@ansible.com>
|
|
|
|
# Copyright (c) 2016 Dell Inc.
|
2017-07-29 21:14:16 +00:00
|
|
|
# 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
|
|
|
|
|
2017-03-06 12:53:35 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2016-12-06 10:35:05 +00:00
|
|
|
|
2016-09-17 17:19:16 +00:00
|
|
|
DOCUMENTATION = """
|
|
|
|
---
|
|
|
|
module: dellos6_facts
|
|
|
|
version_added: "2.2"
|
|
|
|
author: "Abirami N(@abirami-n)"
|
2017-03-06 12:53:35 +00:00
|
|
|
short_description: Collect facts from remote devices running Dell EMC Networking OS6
|
2016-09-17 17:19:16 +00:00
|
|
|
description:
|
|
|
|
- Collects a base set of device facts from a remote device that
|
|
|
|
is running OS6. This module prepends all of the
|
|
|
|
base network fact keys with C(ansible_net_<fact>). The facts
|
2017-03-06 12:53:35 +00:00
|
|
|
module always collects a base set of facts from the device
|
2016-09-17 17:19:16 +00:00
|
|
|
and can enable or disable collection of additional facts.
|
|
|
|
extends_documentation_fragment: dellos6
|
|
|
|
options:
|
|
|
|
gather_subset:
|
|
|
|
description:
|
2017-03-06 12:53:35 +00:00
|
|
|
- When specified, this argument restricts the facts collected
|
2016-10-13 14:47:50 +00:00
|
|
|
to a given subset. Possible values for this argument include
|
2017-03-06 12:53:35 +00:00
|
|
|
all, hardware, config, and interfaces. You can specify a list of
|
|
|
|
values to include a larger subset. You can also use values with an initial M(!) to specify that a specific subset should
|
2016-09-17 17:19:16 +00:00
|
|
|
not be collected.
|
|
|
|
required: false
|
|
|
|
default: '!config'
|
|
|
|
"""
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
# Collect all facts from the device
|
|
|
|
- dellos6_facts:
|
|
|
|
gather_subset: all
|
|
|
|
|
|
|
|
# Collect only the config and default facts
|
|
|
|
- dellos6_facts:
|
|
|
|
gather_subset:
|
|
|
|
- config
|
|
|
|
|
|
|
|
# Do not collect hardware facts
|
|
|
|
- dellos6_facts:
|
|
|
|
gather_subset:
|
|
|
|
- "!interfaces"
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
ansible_net_gather_subset:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The list of fact subsets collected from the device.
|
|
|
|
returned: Always.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: list
|
|
|
|
|
|
|
|
# default
|
|
|
|
ansible_net_model:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The model name returned from the device.
|
|
|
|
returned: Always.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: str
|
|
|
|
ansible_net_serialnum:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The serial number of the remote device.
|
|
|
|
returned: Always.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: str
|
|
|
|
ansible_net_version:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The operating system version running on the remote device.
|
|
|
|
returned: Always.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: str
|
|
|
|
ansible_net_hostname:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The configured hostname of the device.
|
|
|
|
returned: Always.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: string
|
|
|
|
ansible_net_image:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The image file that the device is running.
|
|
|
|
returned: Always
|
2016-09-17 17:19:16 +00:00
|
|
|
type: string
|
|
|
|
|
|
|
|
# hardware
|
|
|
|
ansible_net_memfree_mb:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The available free memory on the remote device in MB.
|
|
|
|
returned: When hardware is configured.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: int
|
|
|
|
ansible_net_memtotal_mb:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The total memory on the remote device in MB.
|
|
|
|
returned: When hardware is configured.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: int
|
|
|
|
|
|
|
|
# config
|
|
|
|
ansible_net_config:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The current active config from the device.
|
|
|
|
returned: When config is configured.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: str
|
|
|
|
|
|
|
|
# interfaces
|
|
|
|
ansible_net_interfaces:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: A hash of all interfaces running on the system.
|
|
|
|
returned: When interfaces is configured.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: dict
|
|
|
|
ansible_net_neighbors:
|
2017-03-06 12:53:35 +00:00
|
|
|
description: The list of LLDP neighbors from the remote device.
|
|
|
|
returned: When interfaces is configured.
|
2016-09-17 17:19:16 +00:00
|
|
|
type: dict
|
|
|
|
|
|
|
|
"""
|
|
|
|
import re
|
2017-03-30 13:26:32 +00:00
|
|
|
|
2017-07-29 21:14:16 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2017-03-30 13:26:32 +00:00
|
|
|
from ansible.module_utils.dellos6 import run_commands
|
|
|
|
from ansible.module_utils.dellos6 import dellos6_argument_spec, check_args
|
|
|
|
from ansible.module_utils.six import iteritems
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FactsBase(object):
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
COMMANDS = list()
|
|
|
|
|
|
|
|
def __init__(self, module):
|
|
|
|
self.module = module
|
2016-09-17 17:19:16 +00:00
|
|
|
self.facts = dict()
|
2017-03-30 13:26:32 +00:00
|
|
|
self.responses = None
|
|
|
|
|
|
|
|
def populate(self):
|
|
|
|
self.responses = run_commands(self.module, self.COMMANDS, check_rc=False)
|
|
|
|
|
|
|
|
def run(self, cmd):
|
|
|
|
return run_commands(self.module, cmd, check_rc=False)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Default(FactsBase):
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
COMMANDS = [
|
|
|
|
'show version',
|
|
|
|
'show running-config | include hostname'
|
|
|
|
]
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def populate(self):
|
2017-03-30 13:26:32 +00:00
|
|
|
super(Default, self).populate()
|
|
|
|
data = self.responses[0]
|
2016-09-17 17:19:16 +00:00
|
|
|
self.facts['version'] = self.parse_version(data)
|
|
|
|
self.facts['serialnum'] = self.parse_serialnum(data)
|
|
|
|
self.facts['model'] = self.parse_model(data)
|
|
|
|
self.facts['image'] = self.parse_image(data)
|
2017-03-30 13:26:32 +00:00
|
|
|
hdata = self.responses[0]
|
2016-09-17 17:19:16 +00:00
|
|
|
self.facts['hostname'] = self.parse_hostname(hdata)
|
|
|
|
|
|
|
|
def parse_version(self, data):
|
|
|
|
match = re.search(r'HW Version(.+)\s(\d+)', data)
|
|
|
|
if match:
|
|
|
|
return match.group(2)
|
|
|
|
|
|
|
|
def parse_hostname(self, data):
|
|
|
|
match = re.search(r'\S+\s(\S+)', data, re.M)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
|
|
|
def parse_model(self, data):
|
|
|
|
match = re.search(r'System Model ID(.+)\s([A-Z0-9]*)\n', data, re.M)
|
|
|
|
if match:
|
|
|
|
return match.group(2)
|
|
|
|
|
|
|
|
def parse_image(self, data):
|
|
|
|
match = re.search(r'Image File(.+)\s([A-Z0-9a-z_.]*)\n', data)
|
|
|
|
if match:
|
|
|
|
return match.group(2)
|
|
|
|
|
|
|
|
def parse_serialnum(self, data):
|
|
|
|
match = re.search(r'Serial Number(.+)\s([A-Z0-9]*)\n', data)
|
|
|
|
if match:
|
|
|
|
return match.group(2)
|
|
|
|
|
|
|
|
|
|
|
|
class Hardware(FactsBase):
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
COMMANDS = [
|
|
|
|
'show memory cpu'
|
|
|
|
]
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def populate(self):
|
2017-03-30 13:26:32 +00:00
|
|
|
super(Hardware, self).populate()
|
|
|
|
data = self.responses[0]
|
2017-11-22 06:22:40 +00:00
|
|
|
match = re.findall(r'\s(\d+)\s', data)
|
2016-09-17 17:19:16 +00:00
|
|
|
if match:
|
2017-07-29 21:14:16 +00:00
|
|
|
self.facts['memtotal_mb'] = int(match[0]) // 1024
|
|
|
|
self.facts['memfree_mb'] = int(match[1]) // 1024
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Config(FactsBase):
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
COMMANDS = ['show running-config']
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def populate(self):
|
2017-03-30 13:26:32 +00:00
|
|
|
super(Config, self).populate()
|
|
|
|
self.facts['config'] = self.responses[0]
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Interfaces(FactsBase):
|
2017-03-30 13:26:32 +00:00
|
|
|
COMMANDS = [
|
|
|
|
'show interfaces',
|
|
|
|
'show interfaces status',
|
|
|
|
'show interfaces transceiver properties',
|
|
|
|
'show ip int',
|
|
|
|
'show lldp',
|
|
|
|
'show lldp remote-device all'
|
|
|
|
]
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def populate(self):
|
|
|
|
vlan_info = dict()
|
2017-03-30 13:26:32 +00:00
|
|
|
super(Interfaces, self).populate()
|
|
|
|
data = self.responses[0]
|
2016-09-17 17:19:16 +00:00
|
|
|
interfaces = self.parse_interfaces(data)
|
2017-03-30 13:26:32 +00:00
|
|
|
desc = self.responses[1]
|
|
|
|
properties = self.responses[2]
|
|
|
|
vlan = self.responses[3]
|
2016-09-17 17:19:16 +00:00
|
|
|
vlan_info = self.parse_vlan(vlan)
|
2017-03-30 13:26:32 +00:00
|
|
|
self.facts['interfaces'] = self.populate_interfaces(interfaces, desc, properties)
|
2016-09-17 17:19:16 +00:00
|
|
|
self.facts['interfaces'].update(vlan_info)
|
2017-03-30 13:26:32 +00:00
|
|
|
if 'LLDP is not enabled' not in self.responses[4]:
|
|
|
|
neighbors = self.responses[5]
|
2016-09-17 17:19:16 +00:00
|
|
|
self.facts['neighbors'] = self.parse_neighbors(neighbors)
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
def parse_vlan(self, vlan):
|
|
|
|
facts = dict()
|
2016-09-17 17:19:16 +00:00
|
|
|
vlan_info, vlan_info_next = vlan.split('---------- ----- --------------- --------------- -------')
|
|
|
|
for en in vlan_info_next.splitlines():
|
|
|
|
if en == '':
|
|
|
|
continue
|
2017-11-22 06:22:40 +00:00
|
|
|
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
|
2016-09-17 17:19:16 +00:00
|
|
|
intf = match.group(1)
|
|
|
|
if intf not in facts:
|
|
|
|
facts[intf] = list()
|
|
|
|
fact = dict()
|
2017-11-22 06:22:40 +00:00
|
|
|
matc = re.search(r'^([\w+\s\d]*)\s+(\S+)\s+(\S+)', en)
|
2016-09-17 17:19:16 +00:00
|
|
|
fact['address'] = matc.group(2)
|
|
|
|
fact['masklen'] = matc.group(3)
|
|
|
|
facts[intf].append(fact)
|
2017-01-27 23:20:31 +00:00
|
|
|
return facts
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def populate_interfaces(self, interfaces, desc, properties):
|
|
|
|
facts = dict()
|
2016-12-12 23:16:23 +00:00
|
|
|
for key, value in interfaces.items():
|
2016-09-17 17:19:16 +00:00
|
|
|
intf = dict()
|
2017-03-30 13:26:32 +00:00
|
|
|
intf['description'] = self.parse_description(key, desc)
|
2016-09-17 17:19:16 +00:00
|
|
|
intf['macaddress'] = self.parse_macaddress(value)
|
|
|
|
intf['mtu'] = self.parse_mtu(value)
|
|
|
|
intf['bandwidth'] = self.parse_bandwidth(value)
|
2017-03-30 13:26:32 +00:00
|
|
|
intf['mediatype'] = self.parse_mediatype(key, properties)
|
2016-09-17 17:19:16 +00:00
|
|
|
intf['duplex'] = self.parse_duplex(value)
|
|
|
|
intf['lineprotocol'] = self.parse_lineprotocol(value)
|
|
|
|
intf['operstatus'] = self.parse_operstatus(value)
|
2017-03-30 13:26:32 +00:00
|
|
|
intf['type'] = self.parse_type(key, properties)
|
2016-09-17 17:19:16 +00:00
|
|
|
facts[key] = intf
|
|
|
|
return facts
|
|
|
|
|
|
|
|
def parse_neighbors(self, neighbors):
|
|
|
|
facts = dict()
|
|
|
|
neighbor, neighbor_next = neighbors.split('--------- ------- ------------------- ----------------- -----------------')
|
|
|
|
for en in neighbor_next.splitlines():
|
|
|
|
if en == '':
|
|
|
|
continue
|
|
|
|
intf = self.parse_lldp_intf(en.split()[0])
|
|
|
|
if intf not in facts:
|
|
|
|
facts[intf] = list()
|
|
|
|
fact = dict()
|
|
|
|
fact['port'] = self.parse_lldp_port(en.split()[3])
|
2017-03-30 13:26:32 +00:00
|
|
|
if (len(en.split()) > 4):
|
|
|
|
fact['host'] = self.parse_lldp_host(en.split()[4])
|
|
|
|
else:
|
|
|
|
fact['host'] = "Null"
|
2016-09-17 17:19:16 +00:00
|
|
|
facts[intf].append(fact)
|
|
|
|
|
|
|
|
return facts
|
|
|
|
|
|
|
|
def parse_interfaces(self, data):
|
|
|
|
parsed = dict()
|
|
|
|
for line in data.split('\n'):
|
|
|
|
if len(line) == 0:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
match = re.match(r'Interface Name(.+)\s([A-Za-z0-9/]*)', line)
|
|
|
|
if match:
|
|
|
|
key = match.group(2)
|
|
|
|
parsed[key] = line
|
|
|
|
else:
|
|
|
|
parsed[key] += '\n%s' % line
|
|
|
|
return parsed
|
|
|
|
|
|
|
|
def parse_description(self, key, desc):
|
|
|
|
desc, desc_next = desc.split('--------- --------------- ------ ------- ---- ------ ----- -- -------------------')
|
2017-03-30 13:26:32 +00:00
|
|
|
if desc_next.find('Oob') > 0:
|
|
|
|
desc_val, desc_info = desc_next.split('Oob')
|
|
|
|
elif desc_next.find('Port') > 0:
|
|
|
|
desc_val, desc_info = desc_next.split('Port')
|
2016-09-17 17:19:16 +00:00
|
|
|
for en in desc_val.splitlines():
|
|
|
|
if key in en:
|
2017-11-22 06:22:40 +00:00
|
|
|
match = re.search(r'^(\S+)\s+(\S+)', en)
|
2017-03-30 13:26:32 +00:00
|
|
|
if match.group(2) in ['Full', 'N/A']:
|
2016-09-17 17:19:16 +00:00
|
|
|
return "Null"
|
|
|
|
else:
|
|
|
|
return match.group(2)
|
|
|
|
|
|
|
|
def parse_macaddress(self, data):
|
|
|
|
match = re.search(r'Burned MAC Address(.+)\s([A-Z0-9.]*)\n', data)
|
|
|
|
if match:
|
|
|
|
return match.group(2)
|
|
|
|
|
|
|
|
def parse_mtu(self, data):
|
|
|
|
match = re.search(r'MTU Size(.+)\s(\d+)\n', data)
|
|
|
|
if match:
|
|
|
|
return int(match.group(2))
|
|
|
|
|
|
|
|
def parse_bandwidth(self, data):
|
2017-03-30 13:26:32 +00:00
|
|
|
match = re.search(r'Port Speed\s*[:\s\.]+\s(\d+)\n', data)
|
2016-09-17 17:19:16 +00:00
|
|
|
if match:
|
2017-03-30 13:26:32 +00:00
|
|
|
return int(match.group(1))
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def parse_duplex(self, data):
|
|
|
|
match = re.search(r'Port Mode\s([A-Za-z]*)(.+)\s([A-Za-z/]*)\n', data)
|
|
|
|
if match:
|
|
|
|
return match.group(3)
|
|
|
|
|
|
|
|
def parse_mediatype(self, key, properties):
|
|
|
|
mediatype, mediatype_next = properties.split('--------- ------- --------------------- --------------------- --------------')
|
2017-03-30 13:26:32 +00:00
|
|
|
flag = 1
|
2016-09-17 17:19:16 +00:00
|
|
|
for en in mediatype_next.splitlines():
|
|
|
|
if key in en:
|
2017-03-30 13:26:32 +00:00
|
|
|
flag = 0
|
2017-11-22 06:22:40 +00:00
|
|
|
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
|
2016-09-17 17:19:16 +00:00
|
|
|
if match:
|
|
|
|
strval = match.group(3)
|
2017-07-29 21:14:16 +00:00
|
|
|
return strval
|
2017-03-30 13:26:32 +00:00
|
|
|
if flag == 1:
|
2016-09-17 17:19:16 +00:00
|
|
|
return "null"
|
2017-01-27 23:45:23 +00:00
|
|
|
|
2016-09-17 17:19:16 +00:00
|
|
|
def parse_type(self, key, properties):
|
|
|
|
type_val, type_val_next = properties.split('--------- ------- --------------------- --------------------- --------------')
|
2017-03-30 13:26:32 +00:00
|
|
|
flag = 1
|
2016-09-17 17:19:16 +00:00
|
|
|
for en in type_val_next.splitlines():
|
|
|
|
if key in en:
|
2017-03-30 13:26:32 +00:00
|
|
|
flag = 0
|
2017-11-22 06:22:40 +00:00
|
|
|
match = re.search(r'^(\S+)\s+(\S+)\s+(\S+)', en)
|
2016-09-17 17:19:16 +00:00
|
|
|
if match:
|
|
|
|
strval = match.group(2)
|
2017-07-29 21:14:16 +00:00
|
|
|
return strval
|
2017-03-30 13:26:32 +00:00
|
|
|
if flag == 1:
|
2016-09-17 17:19:16 +00:00
|
|
|
return "null"
|
|
|
|
|
|
|
|
def parse_lineprotocol(self, data):
|
2017-03-30 13:26:32 +00:00
|
|
|
data = data.splitlines()
|
|
|
|
for d in data:
|
|
|
|
match = re.search(r'^Link Status\s*[:\s\.]+\s(\S+)', d)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def parse_operstatus(self, data):
|
2017-03-30 13:26:32 +00:00
|
|
|
data = data.splitlines()
|
|
|
|
for d in data:
|
|
|
|
match = re.search(r'^Link Status\s*[:\s\.]+\s(\S+)', d)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
def parse_lldp_intf(self, data):
|
|
|
|
match = re.search(r'^([A-Za-z0-9/]*)', data)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
|
|
|
def parse_lldp_host(self, data):
|
2017-03-30 13:26:32 +00:00
|
|
|
match = re.search(r'^([A-Za-z0-9-]*)', data)
|
2016-09-17 17:19:16 +00:00
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
|
|
|
def parse_lldp_port(self, data):
|
|
|
|
match = re.search(r'^([A-Za-z0-9/]*)', data)
|
|
|
|
if match:
|
|
|
|
return match.group(1)
|
|
|
|
|
|
|
|
|
|
|
|
FACT_SUBSETS = dict(
|
|
|
|
default=Default,
|
|
|
|
hardware=Hardware,
|
|
|
|
interfaces=Interfaces,
|
|
|
|
config=Config,
|
|
|
|
)
|
|
|
|
|
|
|
|
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
|
2016-09-17 17:19:16 +00:00
|
|
|
def main():
|
2017-03-30 13:26:32 +00:00
|
|
|
"""main entry point for module execution
|
|
|
|
"""
|
|
|
|
argument_spec = dict(
|
2016-09-17 17:19:16 +00:00
|
|
|
gather_subset=dict(default=['!config'], type='list')
|
|
|
|
)
|
2017-03-30 13:26:32 +00:00
|
|
|
|
|
|
|
argument_spec.update(dellos6_argument_spec)
|
|
|
|
|
|
|
|
module = AnsibleModule(argument_spec=argument_spec,
|
|
|
|
supports_check_mode=True)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
gather_subset = module.params['gather_subset']
|
|
|
|
|
|
|
|
runable_subsets = set()
|
|
|
|
exclude_subsets = set()
|
|
|
|
|
|
|
|
for subset in gather_subset:
|
|
|
|
if subset == 'all':
|
|
|
|
runable_subsets.update(VALID_SUBSETS)
|
|
|
|
continue
|
|
|
|
|
|
|
|
if subset.startswith('!'):
|
|
|
|
subset = subset[1:]
|
|
|
|
if subset == 'all':
|
|
|
|
exclude_subsets.update(VALID_SUBSETS)
|
|
|
|
continue
|
|
|
|
exclude = True
|
|
|
|
else:
|
|
|
|
exclude = False
|
|
|
|
|
|
|
|
if subset not in VALID_SUBSETS:
|
|
|
|
module.fail_json(msg='Bad subset')
|
|
|
|
|
|
|
|
if exclude:
|
|
|
|
exclude_subsets.add(subset)
|
|
|
|
else:
|
|
|
|
runable_subsets.add(subset)
|
|
|
|
|
|
|
|
if not runable_subsets:
|
|
|
|
runable_subsets.update(VALID_SUBSETS)
|
|
|
|
|
|
|
|
runable_subsets.difference_update(exclude_subsets)
|
|
|
|
runable_subsets.add('default')
|
|
|
|
|
|
|
|
facts = dict()
|
|
|
|
facts['gather_subset'] = list(runable_subsets)
|
|
|
|
|
|
|
|
instances = list()
|
|
|
|
for key in runable_subsets:
|
2017-03-30 13:26:32 +00:00
|
|
|
instances.append(FACT_SUBSETS[key](module))
|
2016-09-17 17:19:16 +00:00
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
for inst in instances:
|
|
|
|
inst.populate()
|
|
|
|
facts.update(inst.facts)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
|
|
|
ansible_facts = dict()
|
2017-03-30 13:26:32 +00:00
|
|
|
for key, value in iteritems(facts):
|
2016-09-17 17:19:16 +00:00
|
|
|
key = 'ansible_net_%s' % key
|
|
|
|
ansible_facts[key] = value
|
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
warnings = list()
|
|
|
|
check_args(module, warnings)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
2017-03-30 13:26:32 +00:00
|
|
|
module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
|
2016-09-17 17:19:16 +00:00
|
|
|
|
2017-07-29 21:14:16 +00:00
|
|
|
|
2016-09-17 17:19:16 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|