Does this work?  I think it'd try to run a command called "sudo puppetrun" rather than "sudo" with the argument "puppetrun".  You might want: puppet_cmd = ["sudo", puppetrun, hosts.map ..... ].flatten`