From dbf412b77cac434256f0a62f222256ec3da6e5e2 Mon Sep 17 00:00:00 2001 From: Tim G Date: Tue, 1 Apr 2014 21:09:08 +1000 Subject: [PATCH 1/3] Bugfix, fix crontab commands on HP-UX --- library/system/cron | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/system/cron b/library/system/cron index 15c21fb157d..902442b5d5f 100644 --- a/library/system/cron +++ b/library/system/cron @@ -353,6 +353,8 @@ class CronTab(object): if self.user: if platform.system() == 'SunOS': return "su %s -c '%s -l'" % (pipes.quote(self.user), pipes.quote(CRONCMD)) + elif platform.system() == 'HP-UX': + return "%s %s %s" % (CRONCMD , '-l', pipes.quote(self.user)) else: user = '-u %s' % pipes.quote(self.user) return "%s %s %s" % (CRONCMD , user, '-l') @@ -363,7 +365,7 @@ class CronTab(object): """ user = '' if self.user: - if platform.system() == 'SunOS': + if platform.system() in ['SunOS', 'HP-UX']: return "chown %s %s ; su '%s' -c '%s %s'" % (pipes.quote(self.user), pipes.quote(path), pipes.quote(self.user), CRONCMD, pipes.quote(path)) else: user = '-u %s' % pipes.quote(self.user) From 285d4f3fa69b6b95ce9ce35684a0e8fc26cce2a0 Mon Sep 17 00:00:00 2001 From: Tim G Date: Tue, 1 Apr 2014 21:55:29 +1000 Subject: [PATCH 2/3] If memory not available in syslog.log, catch error, attempt to find it with adb --- lib/ansible/module_utils/facts.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index c6e64fc4e60..b97260d77bd 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1248,9 +1248,17 @@ class HPUX(Hardware): data = int(re.sub(' +',' ',out).split(' ')[5].strip()) self.facts['memfree_mb'] = pagesize * data / 1024 / 1024 if self.facts['architecture'] == '9000/800': - rc, out, err = module.run_command("grep Physical /var/adm/syslog/syslog.log") - data = re.search('.*Physical: ([0-9]*) Kbytes.*',out).groups()[0].strip() - self.facts['memtotal_mb'] = int(data) / 1024 + try: + rc, out, err = module.run_command("grep Physical /var/adm/syslog/syslog.log") + data = re.search('.*Physical: ([0-9]*) Kbytes.*',out).groups()[0].strip() + self.facts['memtotal_mb'] = int(data) / 1024 + except AttributeError: + #For systems where memory details aren't sent to syslog or the log has rotated, use parsed + #adb output. Unfortunatley /dev/kmem doesn't have world-read, so this only works as root. + if os.access("/dev/kmem", os.R_OK): + rc, out, err = module.run_command("echo 'phys_mem_pages/D' | adb -k /stand/vmunix /dev/kmem | tail -1 | awk '{print $2}'", use_unsafe_shell=True) + data = out + self.facts['memtotal_mb'] = int(data) / 256 else: rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep Memory", use_unsafe_shell=True) data = re.search('Memory[\ :=]*([0-9]*).*MB.*',out).groups()[0].strip() From c307a73e289cb8cd8a75609a02c9f42b364f0ff8 Mon Sep 17 00:00:00 2001 From: Tim G Date: Tue, 1 Apr 2014 22:36:19 +1000 Subject: [PATCH 3/3] Check for errors from adb, may not work on all systems. --- lib/ansible/module_utils/facts.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index b97260d77bd..5a6153fadec 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1257,8 +1257,9 @@ class HPUX(Hardware): #adb output. Unfortunatley /dev/kmem doesn't have world-read, so this only works as root. if os.access("/dev/kmem", os.R_OK): rc, out, err = module.run_command("echo 'phys_mem_pages/D' | adb -k /stand/vmunix /dev/kmem | tail -1 | awk '{print $2}'", use_unsafe_shell=True) - data = out - self.facts['memtotal_mb'] = int(data) / 256 + if not err: + data = out + self.facts['memtotal_mb'] = int(data) / 256 else: rc, out, err = module.run_command("/usr/contrib/bin/machinfo | grep Memory", use_unsafe_shell=True) data = re.search('Memory[\ :=]*([0-9]*).*MB.*',out).groups()[0].strip()