From aaedf0bd73a7addc02ba6e8598da5416044ddcce Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 6 Nov 2016 13:43:31 +0100 Subject: [PATCH] Make facts detection work on OpenBSD with Python3 The traceback is the following: Traceback (most recent call last): File \"/tmp/ansible_8s0bj604/ansible_module_setup.py\", line 134, in main() File \"/tmp/ansible_8s0bj604/ansible_module_setup.py\", line 126, in main data = get_all_facts(module) File \"/tmp/ansible_8s0bj604/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3641, in get_all_facts File \"/tmp/ansible_8s0bj604/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3584, in ansible_facts File \"/tmp/ansible_8s0bj604/ansible_modlib.zip/ansible/module_utils/facts.py\", line 1600, in populate File \"/tmp/ansible_8s0bj604/ansible_modlib.zip/ansible/module_utils/facts.py\", line 1649, in get_memory_facts TypeError: translate() takes exactly one argument (2 given) And the swapctl output is this: # /sbin/swapctl -sk total: 83090 1K-blocks allocated, 0 used, 83090 available The only use of the code is to remove prefix in case they are present, so just replacing them with empty space is sufficient. (cherry picked from commit df145df9628b16042ddd1ec5e87bbf924d7812c1) --- lib/ansible/module_utils/facts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 2229251755e..47d379e79f9 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1624,10 +1624,10 @@ class OpenBSDHardware(Hardware): # total: 69268k bytes allocated = 0k used, 69268k available rc, out, err = self.module.run_command("/sbin/swapctl -sk") if rc == 0: - swaptrans = maketrans(' ', ' ') + swaptrans = maketrans('kmg', ' ') data = out.split() - self.facts['swapfree_mb'] = int(data[-2].translate(swaptrans, "kmg")) // 1024 - self.facts['swaptotal_mb'] = int(data[1].translate(swaptrans, "kmg")) // 1024 + self.facts['swapfree_mb'] = int(data[-2].translate(swaptrans)) // 1024 + self.facts['swaptotal_mb'] = int(data[1].translate(swaptrans)) // 1024 def get_processor_facts(self): processor = []