# Systemd checking if service is enabled at boot time

**URL:** <https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181>\
**Category:** Ansible Project\
**Created:** [July 27, 2018, 8:41pm UTC](https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181 "2018-07-27T20:41:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [July 27, 2018, 8:41pm UTC](https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181/1 "2018-07-27T20:41:15Z")

</div>

I am attempting to only check if a service is set to start at boot time.

My current code:

`

- name: Check zabbix-agent is going to start on boot  
systemd:  
name: “zabbix-agent”  
enabled: yes  
ignore\_errors: yes  
register: zabbix\_agent  
check\_mode: yes

`

The service is currently disabled:  
`[~]# systemctl is-enabled zabbix-agent disabled`

When the playbook runs, it is showing the state as ‘enabled’ under a changed state:

`

hostname\> SUCCESS =\> {  
“changed”: true,  
“enabled”: true,  
“name”: “zabbix-agent”,  
“status”: {  
"Active

`

Whereas it should be reporting ‘enabled: false’ - well, that’s what I’m looking for.

Is this something that can be achieved with the systemd module, or should I use the command module and manually run the command?

For some context: I am creating a ‘reboot check’ script, which will highlight show stoppers for a reboot, like if Nginx/http will start on boot etc for then admins to fix (only if necessary - some services are not supposed to start on boot (like Oracle) on this occasion.

Any advice would be great as I’ve not found anything in the docs.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 27, 2018, 8:45pm UTC](https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181/2 "2018-07-27T20:45:28Z")

</div>

Well, your task forces it to be enabled, which the module then tells  
systemd to do, weirdly it seems to 'succeed' but then still be  
disabled? That seems like a bug or something else is going on.

If you just want to query 'system state' use service\_facts module

---

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [July 27, 2018, 8:50pm UTC](https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181/3 "2018-07-27T20:50:07Z")

</div>

Hey thanks for that super speedy reply!

I think it’s because of the check\_mode - I think I’m using it wrong here as without the check\_mode set to true, it does enable the service.

Is there any options to get more information from the service\_facts module that you know of? I only reports whether the service is running;

`

“zabbix-agent.service”: {  
“name”: “zabbix-agent.service”,  
“source”: “systemd”,  
“state”: “running”  
}

`

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [July 27, 2018, 8:56pm UTC](https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181/4 "2018-07-27T20:56:17Z")

</div>

check mode is telling you 'what would happen'

enabled == true + changed == true means it was not enabled to begin with

---

<div class="post-metadata">

**Author:** ![email](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@email](https://forum.ansible.com/u/email)\
**Post date:** [July 27, 2018, 9:01pm UTC](https://forum.ansible.com/t/systemd-checking-if-service-is-enabled-at-boot-time/28181/5 "2018-07-27T21:01:54Z")

</div>

That’s actually a really nice way of looking at it.

I hadn’t thought of trying to read the output in that way.

A service that _is_ enabled on boot, rsyslog gives me this:

`

=\> {  
**“changed”: false,**  
**“enabled”: true,**  
“invocation”: {  
“module\_args”: {  
“daemon\_reload”: false,  
“enabled”: true,  
“force”: null,  
“masked”: null,  
“name”: “rsyslog”,  
“no\_block”: false,  
“state”: null,  
“user”: false  
}  
},  
“name”: “rsyslog”,

`

Maybe this can work then, I was just doing a debug if statement on `enabled`, where as maybe I should be doing it on `changed`.

Thanks
