inventory broken on old PowerPC Mac

Hello,

I’v found a small bug in inventory when running the inventory on old power PC machintosh :

GATHERING FACTS ***************************************************************
fatal: [ns2.p2pweb.net] => failed to parse: Traceback (most recent call last):
File “/Users/fabrice/.ansible/tmp/ansible-tmp-1393363917.68-153393865171475/setup”, line 3417, in
main()
File “/Users/fabrice/.ansible/tmp/ansible-tmp-1393363917.68-153393865171475/setup”, line 2342, in main
data = run_setup(module)
File “/Users/fabrice/.ansible/tmp/ansible-tmp-1393363917.68-153393865171475/setup”, line 2283, in run_setup
facts = ansible_facts()
File “/Users/fabrice/.ansible/tmp/ansible-tmp-1393363917.68-153393865171475/setup”, line 2273, in ansible_facts
facts.update(Hardware().populate())
File “/Users/fabrice/.ansible/tmp/ansible-tmp-1393363917.68-153393865171475/setup”, line 1347, in populate
self.get_cpu_facts()
File “/Users/fabrice/.ansible/tmp/ansible-tmp-1393363917.68-153393865171475/setup”, line 1369, in get_cpu_facts
self.facts[‘processor’] = self.sysctl[‘machdep.cpu.brand_string’]
KeyError: ‘machdep.cpu.brand_string’

The problem is that on powerPC machines, sysctl doesn’t know about machdep.

Instead, you may use : ‘hw.model’ and ‘hw.ncpu’

This can be corrected in the file library/system/setup with something like that :

class Darwin(Hardware):
“”"
Darwin-specific subclass of Hardware. Defines memory and CPU facts:

  • processor
  • processor_cores
  • memtotal_mb
  • memfree_mb
  • model
  • osversion
  • osrevision
    “”"
    platform = ‘Darwin’

def init(self):
Hardware.init(self)

def populate(self):
self.sysctl = self.get_sysctl()
self.get_mac_facts()
self.get_cpu_facts()
self.get_memory_facts()
return self.facts

def get_sysctl(self):
rc, out, err = module.run_command([“/usr/sbin/sysctl”, “hw”, “machdep”, “kern”])
if rc != 0:
return dict()
sysctl = dict()
for line in out.splitlines():
if line.rstrip(“\n”):
(key, value) = re.split(’ = |: ', line, maxsplit=1)
sysctl[key] = value.strip()
return sysctl

def get_mac_facts(self):
self.facts[‘model’] = self.sysctl[‘hw.model’]
self.facts[‘osversion’] = self.sysctl[‘kern.osversion’]
self.facts[‘osrevision’] = self.sysctl[‘kern.osrevision’]

def get_cpu_facts(self):

Thanks for the report, can you please file this on github so we don’t lose track?

Much appreciated!

I knew I’d find a reason for keeping the old G5 around.

Hi,

My code was just a quick fix, and you solution is clearly better

Thanks

–fabrice