How to execute remote commands on linux and update return value?

As part of automation in gitlab ci.

I am running a terraform template and creating a linux machine.

After that, I need to run few commands on the remote machine. I am running those using the ssh remote command. But at the end, even if it is failure, it is showing as successful.

Please let me know how to setup this kind of environment. Installing any tool as a step is also feasible