How to test the remote execution?

How do you test remote execution of a module?

Simple example.

I wrote an integration test for the hostname module. Running the test (as root) on my test VM works. But that’s a local test. I want to test the remote execution of the hostname module.

Ansible works to build this long string of the command to execute on the remote host and each part looks correct it’s only when you send the command over to the remote host via ssh does it fail. The “sending it over” is the part I’m looking to testing.

I’m trying to figure out why the same ssh command displayed in verbose output doesn’t work via ssh but does work when I cut-n-paste just the command part into the remote machine’s shell.

This is related to https://github.com/ansible/ansible/issues/11808 but in general I’d like to know how to do this sort of testing.