# How to detect whether the init system is systemd or not in a module?

**URL:** <https://forum.ansible.com/t/how-to-detect-whether-the-init-system-is-systemd-or-not-in-a-module/22172>\
**Category:** Ansible Developer\
**Created:** [July 30, 2016, 1:57pm UTC](https://forum.ansible.com/t/how-to-detect-whether-the-init-system-is-systemd-or-not-in-a-module/22172 "2016-07-30T13:57:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hiroaki\_Nakamura](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@Hiroaki\_Nakamura](https://forum.ansible.com/u/Hiroaki_Nakamura)\
**Post date:** [July 30, 2016, 1:57pm UTC](https://forum.ansible.com/t/how-to-detect-whether-the-init-system-is-systemd-or-not-in-a-module/22172/1 "2016-07-30T13:57:03Z")

</div>

Hi,

In the hostname module [http://docs.ansible.com/ansible/hostname\_module.html](http://docs.ansible.com/ansible/hostname_module.html)  
I'd like to detect whether the init system is systemd or not in a module.  
[https://github.com/ansible/ansible-modules-core/issues/573#issuecomment-235756879](https://github.com/ansible/ansible-modules-core/issues/573#issuecomment-235756879)

How can I do that?

I found the method get\_service\_mgr\_facts method in Facts class.  
[https://github.com/ansible/ansible/blob/123d54e736520c59d8c7afdcb1c6526df501b174/lib/ansible/module\_utils/facts.py#L351-L400](https://github.com/ansible/ansible/blob/123d54e736520c59d8c7afdcb1c6526df501b174/lib/ansible/module_utils/facts.py#L351-L400)

Is this usable from a module?

Thanks!  
Hiroaki

---

<div class="post-metadata">

**Author:** ![Hiroaki\_Nakamura](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@Hiroaki\_Nakamura](https://forum.ansible.com/u/Hiroaki_Nakamura)\
**Post date:** [August 1, 2016, 2:41pm UTC](https://forum.ansible.com/t/how-to-detect-whether-the-init-system-is-systemd-or-not-in-a-module/22172/2 "2016-08-01T14:41:49Z")

</div>

Before I sent my previous post, I read  
[http://unix.stackexchange.com/a/278965](http://unix.stackexchange.com/a/278965)  
and thought I could use python popen2 or AnsibleModule.run\_command  
with the command  
ps -p 1 -o comm=

```auto
# ps -p 1 -o comm=
systemd

```

Then I found  
I found the method get\_service\_mgr\_facts method in Facts class.  
[https://github.com/ansible/ansible/blob/123d54e736520c59d8c7afdcb1c6526df501b174/lib/ansible/module\_utils/facts.py#L351-L400](https://github.com/ansible/ansible/blob/123d54e736520c59d8c7afdcb1c6526df501b174/lib/ansible/module_utils/facts.py#L351-L400)  
and I thought it may be better to use it if it is usable from a module.
