This may be a stupid question but how does Ansible run modules remotely? I was going through the code a bit and I saw that it uses the Runner library to do so. It first transfers the module to the remote host and then executes it. I am guessing that it copies it to /tmp directory, chmod +x <file> and then executes it.
Not "/tmp" specifically, but "a temp directory", yes. Depends on the user.
if we wrote modules in ruby or lets say Java, we would actually need to have those executables and the modules already existing on the remote (managed) hosts?
Yes, Ruby can't run without a ruby interpreter, and we do execute modules on the client (because they have to change stuff).
I don't expect anyone to be writing them in pure Java.