gcloud
Install Google Cloud SDK
Branch | Pipeline |
---|---|
master |
This Ansible role to install Google Cloud SDK on Ubuntu and macOS development machines.
Do not use this on production servers.
Installation location
The role installs Cloud SDK by default into ~/google-cloud-sdk
.
To install to another location, change the gcloud_install_dir
variable. It
will be used as the installation directory relative to the user home directory.
For example to install into ~/opt/google-cloud-sdk
, you can set:
# Install to ~/opt/google-cloud-sdk
gcloud_install_dir: "/opt"
For backwards compatibility, the role will automatically detect existing
installation in ~/opt/google-cloud-sdk
and default to this location
if found.
Prefer Python 3
The current Google Cloud SDK installer will look for available Python versions
and prefer python2
over python3
.
You can enable python3
to be preferred over python2
during install.
gcloud_prefer_python3: true
Install using package manager
To install Cloud SDK from the package manager where available, enable it in Ansible configuration:
# Install Cloud SDK from APT
gcloud_install_from_package_manager: true
This is only supported on Debian-based systems with APT repositories.
Changes to shell config files
This role makes changes to the .bashrc
and .zshrc
files if these exist in
your home directory. It will resolve any symbolic links to your dotfiles
when making changes.
Code completion for gcloud
command is loaded with all installation options.
If you're managing your shell scripts .dotfiles
or are using a framework, you
should set gcloud_setup_shell
to false
and update these files yourself to
keep them clean.
# Do not mess with my dotfiles!
gcloud_setup_shell: false
Configuring bash manually
Reference .bashrc
configuration when installed into
~/google-cloud-sdk
using the archive:
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 a export CLOUDSDK_ROOT_DIR=
line, the file
will not be modified.
Reference .bashrc
configuration when installed from APT:
if [ -d "/usr/share/google-cloud-sdk" ]; then
# Enable zsh completion for gcloud.
source /usr/share/google-cloud-sdk/completion.bash.inc
fi
Configuring zsh manually
Reference .zshrc
configuration when installed into
~/google-cloud-sdk
using the archive:
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 a export CLOUDSDK_ROOT_DIR=
line, the file
will not be modified.
Reference .zshrc
configuration when installed from APT:
if [ -d "/usr/share/google-cloud-sdk" ]; then
# Enable zsh completion for gcloud.
source /usr/share/google-cloud-sdk/completion.zsh.inc
fi
Update release
Update Cloud SDK version in Ansible variables:
make update
Coding style
Install pre-commit hooks and validate coding style:
make lint
Run tests
Run tests in Ubuntu and Debian using Docker:
make test
License
Contributions
Installation script is based on ansible/role-install-gcloud Ansible role by @chouseknecht.