From 2219339dd50fe586fe15c42ea652ab51d2d4b450 Mon Sep 17 00:00:00 2001 From: "Joe (rook)" <joe.talerico@gmail.com> Date: Sun, 24 Jul 2016 21:39:47 -0400 Subject: [PATCH] Adding ethtool info to Ansible interface facts (#16513) This will give the user details on how the interfaces are configured. They user could query to see if TSO, GSO, etc are enbaled on an interface. --- lib/ansible/module_utils/facts.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 9866b5ce72f..797d5d9ca3c 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -188,7 +188,7 @@ class Facts(object): if not cached_facts: self.facts = {} else: - self.facts = cached_facts + self.facts = cached_facts ### TODO: Eventually, these should all get moved to populate(). But # some of the values are currently being used by other subclasses (for # instance, os_family and distribution). Have to sort out what to do @@ -1327,7 +1327,7 @@ class LinuxHardware(Hardware): part['sectorsize'] = get_file_content(part_sysdir + "/queue/hw_sector_size",512) part['size'] = self.module.pretty_bytes((float(part['sectors']) * float(part['sectorsize']))) self.get_holders(part, part_sysdir) - + d['partitions'][partname] = part d['rotational'] = get_file_content(sysdir + "/queue/rotational") @@ -2277,6 +2277,25 @@ class LinuxNetwork(Network): parse_ip_output(primary_data) parse_ip_output(secondary_data, secondary=True) + def parse_ethtool_output(device,output): + interfaces[device]['features'] = {} + for line in output.strip().split('\n'): + if not line: + continue + if line.endswith(":") : + continue + key,value = line.split(": ") + if not value : + continue + interfaces[device]['features'][key.strip().replace('-','_')] = value.strip() + + ethtool_path = self.module.get_bin_path("ethtool") + if ethtool_path: + args = [ethtool_path, '-k', device] + rc, stdout, stderr = self.module.run_command(args) + ethtool_data = stdout + parse_ethtool_output(device,ethtool_data) + # replace : by _ in interface name since they are hard to use in template new_interfaces = {} for i in interfaces: