From df145df9628b16042ddd1ec5e87bbf924d7812c1 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. --- 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 38354572d6c..b0e8e6c3b58 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1647,10 +1647,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 = []