简体   繁体   中英

Problem running a modified startup-script in GCP

I am trying to set up an Instance using an Instance Template in the GCP Deployment Manager. It works fine but upon adding startup-script in metadata, it doesn't.

This is the code (and script) I am trying to run:

gcloud compute instances create my-instance --source-instance-template my-it --zone=northamerica-northeast1-a -.network=my.network --su.net=my-su.net --no-address --metadata=startup-script='sudo /opt/scripts/startup.sh #. /bin/bash sudo htpasswd -c -B -b /etc/nginx/.htpasswd test test'

Here, the following part comes from the instance template itself and I am trying to add in the latter.

sudo /opt/scripts/startup.sh

Any help appreciated, thanks!

GCP documentation says that when creating a VM from an instance template, the default behavior is to create a VM instance precisely as described in the instance template except for the instance name and zone; if you want to override an attribute, you only need to pass the new value. Create a vm instance from an instance template with overrides

You can see from the documentation that gcloud compute instance-templates has the same --metadata and --metadata-from-file flags as gcloud compute instances gcloud compute instance-templates , gcloud compute instance create

So any new value to --metadata when creating a new instance with --source-instance-template=my_template will only override the value from the instance template (no adding). The --metadata-from-file flag maybe me more suitable for your use case( new.sh with the startup-script form instance template + extra steps)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM