markosamuli.gcloud
Install Google Cloud SDK
This guide explains how to install the Google Cloud SDK on Ubuntu and macOS development machines using Ansible. Note: Do not use this on production servers.
Installation Location
By default, the Google Cloud SDK will be installed in the directory ~/google-cloud-sdk
. If you want to install it in a different location, you can change the gcloud_install_dir
variable. For example, to install it in ~/opt/google-cloud-sdk
, set:
# Install to ~/opt/google-cloud-sdk
gcloud_install_dir: "/opt"
The installer will also automatically find any existing installation in ~/opt/google-cloud-sdk
and use that path if available.
Prefer Python 3
The Google Cloud SDK installer prefers python2
over python3
. If you want to use python3
, enable it by adding:
gcloud_prefer_python3: true
Install Using Package Manager
To install the Cloud SDK from your system's package manager (if available), enable it in your Ansible configuration:
# Install Cloud SDK from APT
gcloud_install_from_package_manager: true
This option is only for Debian-based systems with APT repositories.
Changes to Shell Config Files
The installation will modify your .bashrc
and .zshrc
files if they are present in your home directory. It will ensure that any symbolic links to your dotfiles are resolved.
The configuration will include setups for command completion of the gcloud
command.
If you manage your shell configurations or use a specific framework, set gcloud_setup_shell
to false
to prevent automatic modifications. For example:
# Do not modify my dotfiles!
gcloud_setup_shell: false
Manually Configuring Bash
To manually set up your .bashrc
after installation to ~/google-cloud-sdk
, you can use:
if [ -d "$HOME/google-cloud-sdk" ]; then
export CLOUDSDK_ROOT_DIR="$HOME/google-cloud-sdk"
# Update PATH for the Google Cloud SDK.
source $CLOUDSDK_ROOT_DIR/path.bash.inc
# Enable bash completion for gcloud.
source $CLOUDSDK_ROOT_DIR/completion.bash.inc
fi
If your .bashrc
already has an export CLOUDSDK_ROOT_DIR=
line, it won't be changed.
Manually Configuring Zsh
For .zshrc
configuration after installing to ~/google-cloud-sdk
, use this setup:
if [ -d "$HOME/google-cloud-sdk" ]; then
export CLOUDSDK_ROOT_DIR="$HOME/google-cloud-sdk"
# Update PATH for the Google Cloud SDK.
source $CLOUDSDK_ROOT_DIR/path.zsh.inc
# Enable zsh completion for gcloud.
source $CLOUDSDK_ROOT_DIR/completion.zsh.inc
fi
If your .zshrc
already has an export CLOUDSDK_ROOT_DIR=
line, it won't be modified.
Update Release
To update the Cloud SDK version in Ansible variables, run:
make update
Coding Style
To check the coding style and install pre-commit hooks, use:
make lint
Run Tests
To run tests in Ubuntu and Debian using Docker, run:
make test
License
This project is licensed under the MIT License.
Contributions
This installation script is based on the [ansible/role-install-gcloud] Ansible role by [@chouseknecht].