Systemd checking if service is enabled at boot time

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

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

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

check mode is telling you 'what would happen'

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

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