Gcloud - How to automate installation of gcloud on a server?

和自甴很熟 提交于 2019-12-03 16:46:57

There are two separate problems here.

First, how do you install without prompts:

  1. Download the google cloud sdk tar file. This can be found right under the curl command on https://cloud.google.com/sdk/
  2. Untar and cd into the newly created directory.
  3. run CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./install.sh (or install.bat)

This disables all prompts. If you don't like the way it answers the prompts, you can pre-answer them with flags. If you preanswer all the questions, you don't need the CLOUDSDK_CORE_DISABLE_PROMPTS environment variable set. Run ./install.sh --help for a list of flags.


Now that you have it installed, how do you auth it?

If you are on GCE, you can use the credentials on the machine itself automatically. If not, some setup is required.

Since these are automated installs, you want to give them a server key. If there was a human involved, he can just proceed through the normal flow.

Keys can be downloaded from the developer console under "APIs & auth -> Credentials". Click "New credentials -> Service account key". Google recommends you use a JSON key.

When you have that key, you need to move it to the new server and run:

gcloud auth activate-service-account --key-file servicekey.json
gcloud config set project MYPROJECT

This sequence of commands should help:

file="google-cloud-sdk-101.0.0-linux-x86_64.tar.gz"
link="https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/"

curl -L "$link""$file" | tar xz 
CLOUDSDK_CORE_DISABLE_PROMPTS=1 ./google-cloud-sdk/install.sh
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!