[timezone module] Check if timedatectl command is actually available

This commit is contained in:
tmshn 2016-12-15 12:15:53 +09:00 committed by Brian Coca
parent a532dd915a
commit 112d950794

View file

@ -92,13 +92,14 @@ class Timezone(object):
"""Return the platform-specific subclass.
It does not use load_platform_subclass() because it need to judge based
on whether the `timedatectl` command exists.
on whether the `timedatectl` command exists and available.
Args:
module: The AnsibleModule.
"""
if get_platform() == 'Linux':
if module.get_bin_path('timedatectl') is not None:
timedatectl = module.get_bin_path('timedatectl')
if timedatectl is not None and module.run_command(timedatectl)[0] == 0:
return super(Timezone, SystemdTimezone).__new__(SystemdTimezone)
else:
return super(Timezone, NosystemdTimezone).__new__(NosystemdTimezone)