From c68d81fe4fd0431075008b2676cf9bb21d8d8303 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Sat, 18 Feb 2017 13:05:21 -0500 Subject: [PATCH] added check_ps common function --- lib/ansible/module_utils/service.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/ansible/module_utils/service.py b/lib/ansible/module_utils/service.py index ea1bb15940..be3dcf822c 100644 --- a/lib/ansible/module_utils/service.py +++ b/lib/ansible/module_utils/service.py @@ -202,3 +202,22 @@ def daemonize(module, cmd): return_data += b(data) return pickle.loads(to_text(return_data, errors=errors)) + +def check_ps(module, pattern): + + # Set ps flags + if platform.system() == 'SunOS': + psflags = '-ef' + else: + psflags = 'auxww' + + # Find ps binary + psbin = module.get_bin_path('ps', True) + + (rc, out, err) = module.run_command('%s %s' % (psbin, psflags)) + # If rc is 0, set running as appropriate + if rc == 0: + for line in out.split('\n'): + if pattern in line: + return True + return False