mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix for memory fact gathering
I have a host which started to fail while gathering facts after the addition of expanded memory facts in PR #9839: Traceback (most recent call last): File "/home/ansible/.ansible/tmp/ansible-tmp-1422536976.05-133253824703289/setup", line 4278, in <module> main() File "/home/ansible/.ansible/tmp/ansible-tmp-1422536976.05-133253824703289/setup", line 137, in main data = run_setup(module) File "/home/ansible/.ansible/tmp/ansible-tmp-1422536976.05-133253824703289/setup", line 81, in run_setup facts = ansible_facts(module) File "/home/ansible/.ansible/tmp/ansible-tmp-1422536976.05-133253824703289/setup", line 4217, in ansible_facts facts.update(Hardware().populate()) File "/home/ansible/.ansible/tmp/ansible-tmp-1422536976.05-133253824703289/setup", line 2339, in populate self.get_memory_facts() File "/home/ansible/.ansible/tmp/ansible-tmp-1422536976.05-133253824703289/setup", line 2375, in get_memory_facts 'cached': memstats['swapcached'] KeyError: 'swapcached' My problem host doesn't have SwapCached in /proc/meminfo. It may be better to set defaults for these keys, since the values provided by /proc/meminfo can change from version to version.
This commit is contained in:
parent
fef435cc2a
commit
0c3a273805
1 changed files with 9 additions and 9 deletions
|
@ -635,19 +635,19 @@ class LinuxHardware(Hardware):
|
|||
memstats[key.lower()] = long(val) / 1024
|
||||
self.facts['memory_mb'] = {
|
||||
'real' : {
|
||||
'total': memstats['memtotal'],
|
||||
'used': (memstats['memtotal'] - memstats['memfree']),
|
||||
'free': memstats['memfree']
|
||||
'total': memstats.get('memtotal', 0),
|
||||
'used': (memstats.get('memtotal', 0) - memstats.get('memfree', 0)),
|
||||
'free': memstats.get('memfree', 0)
|
||||
},
|
||||
'nocache' : {
|
||||
'free': memstats['cached'] + memstats['memfree'] + memstats['buffers'],
|
||||
'used': memstats['memtotal'] - (memstats['cached'] + memstats['memfree'] + memstats['buffers'])
|
||||
'free': memstats.get('cached', 0) + memstats.get('memfree', 0) + memstats.get('buffers', 0),
|
||||
'used': memstats.get('memtotal', 0) - (memstats.get('cached', 0) + memstats.get('memfree', 0) + memstats.get('buffers', 0))
|
||||
},
|
||||
'swap' : {
|
||||
'total': memstats['swaptotal'],
|
||||
'free': memstats['swapfree'],
|
||||
'used': memstats['swaptotal'] - memstats['swapfree'],
|
||||
'cached': memstats['swapcached']
|
||||
'total': memstats.get('swaptotal', 0),
|
||||
'free': memstats.get('swapfree', 0),
|
||||
'used': memstats.get('swaptotal', 0) - memstats.get('swapfree', 0),
|
||||
'cached': memstats.get('swapcached', 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue