Currently, if I want to execute something in a virtual machine, I copy the files as follows:
gcloud compute --project <project_id> copy-files --zone <zone_name> /home/roman/source/dir roman@<vm_name>:/some/path
Then I need to SSH into it manually, like this:
gcloud compute --project <project_id> ssh --zone <zone_name> <vm_name>
And then run and execute some command:
cd /some/path python example.py
How to combine steps 2 and 3 together and execute the command remotely?
Note. I want to use gcloud or python api. I do not want to use third-party packages such as Fabric.
ssh google-compute-engine gcloud
Roman
source share