From a93db1948e38217ef4d7e928754e9a9bd59412ac Mon Sep 17 00:00:00 2001
From: Jonathan Davila <jdavila@ansible.com>
Date: Wed, 10 Dec 2014 11:43:37 -0500
Subject: [PATCH] expanded facts

---
 lib/ansible/module_utils/facts.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
index 38082fe854..198b93a282 100644
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -571,6 +571,8 @@ class LinuxHardware(Hardware):
 
     platform = 'Linux'
     MEMORY_FACTS = ['MemTotal', 'SwapTotal', 'MemFree', 'SwapFree']
+    EXTRA_MEMORY_FACTS = ['Buffers', 'Cached', 'SwapCached']
+
 
     def __init__(self):
         Hardware.__init__(self)
@@ -587,6 +589,7 @@ class LinuxHardware(Hardware):
         return self.facts
 
     def get_memory_facts(self):
+        memstats = {}
         if not os.access("/proc/meminfo", os.R_OK):
             return
         for line in open("/proc/meminfo").readlines():
@@ -595,6 +598,26 @@ class LinuxHardware(Hardware):
             if key in LinuxHardware.MEMORY_FACTS:
                 val = data[1].strip().split(' ')[0]
                 self.facts["%s_mb" % key.lower()] = long(val) / 1024
+            if key in LinuxHardware.MEMORY_FACTS or key in LinuxHardware.EXTRA_MEMORY_FACTS:
+                 val = data[1].strip().split(' ')[0]
+                 memstats[key.lower()] = long(val) / 1024
+        self.facts['memory_mb'] = {
+                     'real' : {
+                         'total': memstats['memtotal'],
+                         'used': (memstats['memtotal'] - memstats['memfree']),
+                         'free': memstats['memfree']
+                     },
+                     'nocache' : {
+                         'free': memstats['cached'] + memstats['memfree'] + memstats['buffers'],
+                         'used': memstats['memtotal'] - (memstats['cached'] + memstats['memfree'] + memstats['buffers'])
+                     },
+                     'swap' : {
+                         'total': memstats['swaptotal'],
+                         'free': memstats['swapfree'],
+                         'used': memstats['swaptotal'] - memstats['swapfree'],
+                         'cached': memstats['swapcached']
+                     }
+                 }
 
     def get_cpu_facts(self):
         i = 0