From 6622b0532606aa6a3befe90b25e76ccd3b43c490 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz <ricardo.carrillo.cruz@gmail.com> Date: Tue, 21 Feb 2017 14:38:35 +0100 Subject: [PATCH] Fix memory ios facts (#21696) In order to populate the total and free mem of an IOS device, we run the 'show memory statistics' command. The output shows something similar to: Head Total(b) Used(b) Free(b) Lowest(b) Largest(b) Processor BEAE880 335215488 64044364 271171124 268918092 268463852 I/O 8DAE880 51380224 41880736 9499488 9461552 9352252 We need to just parse the line containing 'Processor' and get the first and third number for total and free mem, instaed for first and second as the code wrongly does. --- lib/ansible/modules/network/ios/ios_facts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/network/ios/ios_facts.py b/lib/ansible/modules/network/ios/ios_facts.py index e0ce15c5638..79da719b2ce 100644 --- a/lib/ansible/modules/network/ios/ios_facts.py +++ b/lib/ansible/modules/network/ios/ios_facts.py @@ -222,10 +222,12 @@ class Hardware(FactsBase): data = self.responses[1] if data: - match = re.findall(r'\s(\d+)\s', data) + processor_line = [l for l in data.splitlines() + if 'Processor' in l].pop() + match = re.findall(r'\s(\d+)\s', processor_line) if match: self.facts['memtotal_mb'] = int(match[0]) / 1024 - self.facts['memfree_mb'] = int(match[1]) / 1024 + self.facts['memfree_mb'] = int(match[3]) / 1024 def parse_filesystems(self, data): return re.findall(r'^Directory of (\S+)/', data, re.M)