mirror of
https://github.com/ansible/awx.git
synced 2026-03-08 05:01:09 -02:30
RHEL5 compatibility and handling of error scenarios
This commit is contained in:
@@ -97,13 +97,23 @@ class ServiceScanService(BaseService):
|
|||||||
#print '%s --status-all | grep -E "is (running|stopped)"' % service_path
|
#print '%s --status-all | grep -E "is (running|stopped)"' % service_path
|
||||||
p = re.compile('(?P<service>.*?)\s+[0-9]:(?P<rl0>on|off)\s+[0-9]:(?P<rl1>on|off)\s+[0-9]:(?P<rl2>on|off)\s+[0-9]:(?P<rl3>on|off)\s+[0-9]:(?P<rl4>on|off)\s+[0-9]:(?P<rl5>on|off)\s+[0-9]:(?P<rl6>on|off)')
|
p = re.compile('(?P<service>.*?)\s+[0-9]:(?P<rl0>on|off)\s+[0-9]:(?P<rl1>on|off)\s+[0-9]:(?P<rl2>on|off)\s+[0-9]:(?P<rl3>on|off)\s+[0-9]:(?P<rl4>on|off)\s+[0-9]:(?P<rl5>on|off)\s+[0-9]:(?P<rl6>on|off)')
|
||||||
rc, stdout, stderr = self.module.run_command('%s' % chkconfig_path, use_unsafe_shell=True)
|
rc, stdout, stderr = self.module.run_command('%s' % chkconfig_path, use_unsafe_shell=True)
|
||||||
# extra flags needed for SLES11
|
# Check for special cases where stdout does not fit pattern
|
||||||
if not any(p.match(line) for line in stdout.split('\n')):
|
match_any = False
|
||||||
# If p pattern is not found but p_simple is, we have single-column ouptut
|
for line in stdout.split('\n'):
|
||||||
|
if p.match(line):
|
||||||
|
match_any = True
|
||||||
|
if not match_any:
|
||||||
p_simple = re.compile('(?P<service>.*?)\s+(?P<rl0>on|off)')
|
p_simple = re.compile('(?P<service>.*?)\s+(?P<rl0>on|off)')
|
||||||
if any(p_simple.match(line) for line in stdout.split('\n')):
|
match_any = False
|
||||||
# Try extra flags " -l --allservices" to output all columns
|
for line in stdout.split('\n'):
|
||||||
|
if p_simple.match(line):
|
||||||
|
match_any = True
|
||||||
|
if match_any:
|
||||||
|
# Try extra flags " -l --allservices" needed for SLES11
|
||||||
rc, stdout, stderr = self.module.run_command('%s -l --allservices' % chkconfig_path, use_unsafe_shell=True)
|
rc, stdout, stderr = self.module.run_command('%s -l --allservices' % chkconfig_path, use_unsafe_shell=True)
|
||||||
|
elif '--list' in stderr:
|
||||||
|
# Extra flag needed for RHEL5
|
||||||
|
rc, stdout, stderr = self.module.run_command('%s --list' % chkconfig_path, use_unsafe_shell=True)
|
||||||
for line in stdout.split('\n'):
|
for line in stdout.split('\n'):
|
||||||
m = p.match(line)
|
m = p.match(line)
|
||||||
if m:
|
if m:
|
||||||
@@ -116,11 +126,12 @@ class ServiceScanService(BaseService):
|
|||||||
service_state = 'running'
|
service_state = 'running'
|
||||||
#elif rc in (1,3):
|
#elif rc in (1,3):
|
||||||
else:
|
else:
|
||||||
service_state = 'stopped'
|
if 'root' in stderr or 'permission' in stderr.lower() or 'not in sudoers' in stderr.lower():
|
||||||
|
service_state = 'unable to scan, requires root'
|
||||||
|
else:
|
||||||
|
service_state = 'stopped'
|
||||||
service_data = {"name": service_name, "state": service_state, "source": "sysv"}
|
service_data = {"name": service_name, "state": service_state, "source": "sysv"}
|
||||||
services.append(service_data)
|
services.append(service_data)
|
||||||
# rc, stdout, stderr = self.module.run_command("%s --list" % chkconfig_path)
|
|
||||||
# Do something with chkconfig status
|
|
||||||
return services
|
return services
|
||||||
|
|
||||||
class SystemctlScanService(BaseService):
|
class SystemctlScanService(BaseService):
|
||||||
@@ -167,6 +178,8 @@ def main():
|
|||||||
svc = svcmod.gather_services()
|
svc = svcmod.gather_services()
|
||||||
if svc is not None:
|
if svc is not None:
|
||||||
all_services += svc
|
all_services += svc
|
||||||
|
if len(all_services) == 0:
|
||||||
|
module.fail_json(msg="Failed to find any services. Sometimes this solved by running with privilege escalation.")
|
||||||
results = dict(ansible_facts=dict(services=all_services))
|
results = dict(ansible_facts=dict(services=all_services))
|
||||||
module.exit_json(**results)
|
module.exit_json(**results)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user