How to Change the Lid Close Action in Ubuntu Laptop

Edit the systemd-logind config file:

~$ grep Lid /etc/systemd/logind.conf
#HandleLidSwitch=suspend
#HandleLidSwitchExternalPower=suspend
#HandleLidSwitchDocked=ignore
#LidSwitchIgnoreInhibited=yes

HandleLidSwitchDocked=ignore – If your system is inserted in a docking station, or if more than one display is connected, then the action occurs if specified.
HandleLidSwitchExternalPower=suspend – If your system is on external power, the action occurs if specified.
HandleLidSwitch=suspend – For all other cases, the value of HandleLidSwitch will occur if enabled.

ignore – do nothing.
poweroff – shutdown machine.
reboot – restart the system.
lock – screen lock all running sessions.

Remove '#' at the beginning to enable the line, and change the value!

After changes, save the file and restart the logind service by running command in terminal:

~$ systemctl restart systemd-logind.service