In ubuntu with graphic interface this is too easy, just go to settings -> energy and change the behaviour when plugged or with battery. But in my case I have installed in one old laptop that I use as home server Ubuntu Server so no graphical interface.
So in order to change this behaviour just open the
/etc/systemd/logind.conf file in a text editor as root
Edit HandleLidSwitch to ignore, make sure it’s not commented