diff options
author | James Cassell <code@james.cassell.me> | 2020-02-04 17:32:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-04 17:32:36 -0500 |
commit | 1bb94ec92fe837a30177b192a477522b30132aa1 (patch) | |
tree | aff5302fbb74fd8225c068dde8d4cf24dbb592d4 | |
parent | 4ac89b8ac7120f553c78eafb294c045f3baa8792 (diff) | |
download | ansible-1bb94ec92fe837a30177b192a477522b30132aa1.tar.gz |
service_mgr: detect systemd, even offline (#66071)
* service_mgr: detect systemd, even offline
* service_mgr=systemd iff /sbin/init is symlink
-rw-r--r-- | changelogs/fragments/service-mgr-systemd-offline.yml | 3 | ||||
-rw-r--r-- | lib/ansible/module_utils/facts/system/service_mgr.py | 12 |
2 files changed, 15 insertions, 0 deletions
diff --git a/changelogs/fragments/service-mgr-systemd-offline.yml b/changelogs/fragments/service-mgr-systemd-offline.yml new file mode 100644 index 0000000000..dcde9a4e97 --- /dev/null +++ b/changelogs/fragments/service-mgr-systemd-offline.yml @@ -0,0 +1,3 @@ +bugfixes: +- setup - service_mgr - detect systemd even if it isn't running, such as during + a container build diff --git a/lib/ansible/module_utils/facts/system/service_mgr.py b/lib/ansible/module_utils/facts/system/service_mgr.py index cb044fbf72..dc8df68e59 100644 --- a/lib/ansible/module_utils/facts/system/service_mgr.py +++ b/lib/ansible/module_utils/facts/system/service_mgr.py @@ -52,6 +52,16 @@ class ServiceMgrFactCollector(BaseFactCollector): return True return False + @staticmethod + def is_systemd_managed_offline(module): + # tools must be installed + if module.get_bin_path('systemctl'): + # check if /sbin/init is a symlink to systemd + # on SUSE, /sbin/init may be missing if systemd-sysvinit package is not installed. + if os.path.islink('/sbin/init') and os.path.basename(os.readlink('/sbin/init')) == 'systemd': + return True + return False + def collect(self, module=None, collected_facts=None): facts_dict = {} @@ -129,6 +139,8 @@ class ServiceMgrFactCollector(BaseFactCollector): service_mgr_name = 'upstart' elif os.path.exists('/sbin/openrc'): service_mgr_name = 'openrc' + elif self.is_systemd_managed_offline(module=module): + service_mgr_name = 'systemd' elif os.path.exists('/etc/init.d/'): service_mgr_name = 'sysvinit' |