Disable Suspend Mode on Laptop Lid Close with Ansible and Systemd

I have a CentOS 7 laptop where every time I close the lid, the system suspends. I’d like to change this behaviour so that nothing would happen instead.

Systemd Login Manager Configuration

Systemd login manager controls how logind handles the system power, reboot and sleep keys and the lid switch to trigger actions such as system power-off, reboot or suspend.

According to the logind.conf man page, HandleLidSwitch= defaults to “suspend”. What we want to do is to set it to “ignore”.

We can do that by using the following ansible play:

- name: Disable suspend on laptop lid close
    path: "/etc/systemd/logind.conf"
    state: present
    regexp: "^HandleLidSwitch="
    line: "HandleLidSwitch=ignore"

This should prevent the system from going into suspend mode on lid close.

Leave a Reply

Your email address will not be published. Required fields are marked *