Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
*.db

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down
20 changes: 12 additions & 8 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
---
# defaults file for role-install-gcloud

gcloud_archive_name: '' # Example: google-cloud-sdk-114.0.0-darwin-x86_64.tar.gz. If present, the archive will be downloaded.
# See https://cloud.google.com/sdk/ to find the archive name you need.
gcloud_archive_name: 'google-cloud-sdk-529.0.0-linux-x86_64.tar.gz' # Example: google-cloud-sdk-114.0.0-darwin-x86_64.tar.gz. If present, the archive will be downloaded.
# See https://cloud.google.com/sdk/ to find the archive name you need.
gcloud_tmp_path: /tmp/install_gcloud # Path where the downloaded archive can be temporarily placed
gcloud_force_download: yes # When downloading the archive, always download the archive, even if it already exists in the temp path.

gcloud_archive_path: '' # Path to the gcloud archive file on the Ansible controller.
gcloud_archive_path: '' # Path to the gcloud archive file on the Ansible controller.
# If present archive will be copied, not downloaded.

gcloud_install_path: "{{ ansible_env.HOME }}" # Path on target node where the unarchived files should land.
gcloud_install_path: "/home/njl/" # Path on target node where the unarchived files should land.

gcloud_usage_reporting: no # Enable usage reporting?
gcloud_profile_path: '' # Path to the user profile login script. Optional.
gcloud_command_completion: yes # Enable bash style command completion in the login script?
gcloud_update_path: yes # Update the PATH when when modifying user's login script.
gcloud_override_components: [] # Override the components that would be installed by default, and install these instead.
gcloud_override_components: [] # Override the components that would be installed by default, and install these instead.

gcloud_additional_components: [kubectl] # Additional components to install by default. Will either be added to the default install
# list, or to the override-components (if provided)
gcloud_debug: yes
gcloud_additional_components: [] # Additional components to install by default. Will either be added to the default install
# list, or to the override-components (if provided)
gcloud_debug: yes


gcloud_keyring_file: /usr/share/keyrings/cloud.google.gpg
gcloud_keyring_url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
gcloud_keyring_tmp_file: /tmp/cloud.google.gpg
1 change: 1 addition & 0 deletions files
18 changes: 18 additions & 0 deletions tasks/authenticate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
- name: Copy the archive from the Ansible controller
copy:
src: "{{ gcloud_credentials }}"
dest: "/home/njl/.config/gcloud/{{ gcloud_credentials }}"
mode: 0600
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --creds-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag --creds-file is incorrect. The correct flag for gcloud auth login with service account credentials is --cred-file (singular).

Suggested change
cmd: "gcloud auth login --creds-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
cmd: "gcloud auth login --cred-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +9
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded path '/home/njl' should be replaced with a variable to make the authentication task reusable across different users.

Suggested change
dest: "/home/njl/.config/gcloud/{{ gcloud_credentials }}"
mode: 0600
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --creds-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
dest: "{{ ansible_env.HOME }}/.config/gcloud/{{ gcloud_credentials }}"
mode: 0600
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --creds-file={{ ansible_env.HOME }}/.config/gcloud/{{ gcloud_credentials }}"

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +9
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded path '/home/njl' should be replaced with a variable to make the authentication task reusable across different users.

Suggested change
dest: "/home/njl/.config/gcloud/{{ gcloud_credentials }}"
mode: 0600
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --creds-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
dest: "{{ ansible_env.HOME }}/.config/gcloud/{{ gcloud_credentials }}"
mode: 0600
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --creds-file={{ ansible_env.HOME }}/.config/gcloud/{{ gcloud_credentials }}"

Copilot uses AI. Check for mistakes.
register: gcloud_auth_status
- name: Check the authentication status
ansible.builtin.debug:
msg: "{{ gcloud_auth_status.stdout }}"
- name: Set the default project
ansible.builtin.shell:
cmd: "gcloud config set project {{ gcloud_project }}"
register: gcloud_project_status

122 changes: 58 additions & 64 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,59 @@
---
- name: Insure temp path exists
file:
path: "{{ gcloud_tmp_path }}"
state: directory

#
# download
#
- name: Download the archive
get_url:
url: "{{ gcloud_archive_url }}/{{ gcloud_archive_name }}"
dest: "{{ gcloud_tmp_path }}/{{ gcloud_archive_name }}"
force: "{{ gcloud_force_download }}"
when: gcloud_archive_name

#
# copy from Ansible controller
#
- name: Copy the archive from the Ansible controller
copy:
src: "{{ gcloud_archive_path }}"
dest: "{{ gcloud_tmp_path }}"
when: gcloud_archive_path

- name: Remove existing google-cloud-sdk dir, it if exists
file:
path: "{{ gcloud_install_path }}/google-cloud-sdk"
state: absent
when: gcloud_archive_name

- set_fact:
archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_name }}"
when: gcloud_archive_name

- set_fact:
archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_path | basename }}"
when: gcloud_archive_path

- name: Unarchive
shell: cd "{{ gcloud_install_path }}" && tar xvzf "{{ archive_path }}"
when: gcloud_archive_name

- name: Build run script
template:
src: "{{ role_path }}/templates/run.j2"
dest: "{{ gcloud_tmp_path }}/run_install.sh"
mode: 0755
tags:
- copy
- download

- name: Install
command: "{{ gcloud_tmp_path }}/run_install.sh"

- name: Remove the archive
file:
path: "{{ archive_path }}"
state: absent

- name: Remove the script
file:
path: "{{ gcloud_tmp_path }}/run_install.sh"
state: absent
when: not gcloud_debug
- name: "Install GCloud Main"
become: true
become_user: root
block:
#
# download
#

- name: "Remove old key"
ansible.builtin.file:
name: "{{ gcloud_keyring_file }}"
state: absent
- name: Download the Keyring
ansible.builtin.get_url:
url: "{{ gcloud_keyring_url }}"
dest: "{{ gcloud_keyring_tmp_file }}"
force: true
mode: "0644"
- name: DeArmor the Keyring
ansible.builtin.shell: "gpg --yes --batch --dearmor -o {{ gcloud_keyring_file }} {{ gcloud_keyring_tmp_file }}"
- name: Somerepo | apt source
ansible.builtin.apt_repository:
repo: "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main"
filename: "google-cloud-sdk"
state: present
- name: Install the Google Cloud SDK
ansible.builtin.apt:
name: google-cloud-cli
state: present
update_cache: true
cache_valid_time: 84600
force_apt_get: true
- name: "config cloud auth "
become: true
become_user: "{{ local_ssh_user }}"
block:
- name: "Add gcloud config"
ansible.builtin.file:
name: "/home/njl/.config/gcloud/"
state: directory
mode: "0700"
- name: Copy the archive from the Ansible controller
ansible.builtin.copy:
src: "{{ gcloud_credentials }}"
dest: "/home/njl/.config/gcloud/{{ gcloud_credentials }}"
mode: "0600"
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --cred-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For service account authentication, use gcloud auth activate-service-account --key-file instead of gcloud auth login --cred-file. The login command is for user authentication, not service accounts.

Suggested change
cmd: "gcloud auth login --cred-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
cmd: "gcloud auth activate-service-account --key-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +50
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded path '/home/njl' should be replaced with a variable like {{ ansible_env.HOME }} or {{ local_ssh_user_home }} to make the role more reusable.

Suggested change
name: "/home/njl/.config/gcloud/"
state: directory
mode: "0700"
- name: Copy the archive from the Ansible controller
ansible.builtin.copy:
src: "{{ gcloud_credentials }}"
dest: "/home/njl/.config/gcloud/{{ gcloud_credentials }}"
mode: "0600"
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --cred-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
name: "{{ ('~' + local_ssh_user + '/.config/gcloud/') | expanduser }}"
state: directory
mode: "0700"
- name: Copy the archive from the Ansible controller
ansible.builtin.copy:
src: "{{ gcloud_credentials }}"
dest: "{{ ('~' + local_ssh_user + '/.config/gcloud/' + gcloud_credentials) | expanduser }}"
mode: "0600"
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --cred-file={{ ('~' + local_ssh_user + '/.config/gcloud/' + gcloud_credentials) | expanduser }}"

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +50
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded path '/home/njl' should be replaced with a variable like {{ ansible_env.HOME }} or {{ local_ssh_user_home }} to make the role more reusable.

Suggested change
name: "/home/njl/.config/gcloud/"
state: directory
mode: "0700"
- name: Copy the archive from the Ansible controller
ansible.builtin.copy:
src: "{{ gcloud_credentials }}"
dest: "/home/njl/.config/gcloud/{{ gcloud_credentials }}"
mode: "0600"
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --cred-file=/home/njl/.config/gcloud/{{ gcloud_credentials }}"
name: "{{ local_ssh_user_home }}/.config/gcloud/"
state: directory
mode: "0700"
- name: Copy the archive from the Ansible controller
ansible.builtin.copy:
src: "{{ gcloud_credentials }}"
dest: "{{ local_ssh_user_home }}/.config/gcloud/{{ gcloud_credentials }}"
mode: "0600"
- name: Authenticate with Google Cloud
ansible.builtin.shell:
cmd: "gcloud auth login --cred-file={{ local_ssh_user_home }}/.config/gcloud/{{ gcloud_credentials }}"

Copilot uses AI. Check for mistakes.
register: gcloud_auth_status
- name: Check the authentication status
ansible.builtin.debug:
msg: "{{ gcloud_auth_status.stdout }}"
- name: Set the default project
ansible.builtin.shell:
cmd: "gcloud config set project {{ gcloud_project }}"
register: gcloud_project_status

86 changes: 86 additions & 0 deletions tasks/raw_install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
- block:
- name: Insure temp path exists
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: 'Insure' should be 'Ensure' in the task name.

Suggested change
- name: Insure temp path exists
- name: Ensure temp path exists

Copilot uses AI. Check for mistakes.
file:
path: "{{ gcloud_tmp_path }}"
state: directory

#
# download
#
- name: Download the archive
get_url:
url: "{{ gcloud_archive_url }}/{{ gcloud_archive_name }}"
dest: "{{ gcloud_tmp_path }}/{{ gcloud_archive_name }}"
force: "{{ gcloud_force_download }}"
- set_fact:
gcloud_archive_path: "{{ gcloud_tmp_path }}/{{ gcloud_archive_name }}"

#
# copy from Ansible controller
#
- name: Copy the archive from the Ansible controller
copy:
src: "{{ gcloud_archive_path }}"
dest: "{{ gcloud_tmp_path }}"
remote_src: yes

- name: Remove existing google-cloud-sdk dir, it if exists
file:
path: "{{ gcloud_install_path }}/google-cloud-sdk"
state: absent

- set_fact:
archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_name }}"

- set_fact:
archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_path | basename }}"

- name: Unarchive
shell: cd "{{ gcloud_install_path }}" && tar xvzf "{{ archive_path }}"

- name: Build run script
template:
src: "{{ role_path }}/templates/run.j2"
dest: "{{ gcloud_tmp_path }}/run_install.sh"
mode: 0755
tags:
- copy
- download

- name: Install
command: "{{ gcloud_tmp_path }}/run_install.sh"

- name: Add configuration directory
file:
path: "{{ gcloud_install_path }}/.config"
state: directory
mode: 0755
- name: Add configuration directory
file:
path: "{{ gcloud_install_path }}/.config/gcloud"
state: directory
mode: 0755
- name: Add configuration directory
file:
path: "{{ gcloud_install_path }}/.config/gcloud/configurations"
state: directory
mode: 0755
- name: Put in default config (not sure we can do the auth...)
template:
src: "default_config.j2"
dest: "{{ gcloud_install_path }}/.config/gcloud/configurations/config_default"
mode: 0644

- name: Remove the archive
file:
path: "{{ archive_path }}"
state: absent

- name: Remove the script
file:
path: "{{ gcloud_tmp_path }}/run_install.sh"
state: absent
when: not gcloud_debug

when: gcloud_archive_name is defined
3 changes: 3 additions & 0 deletions templates/default_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[core]
account = nick.lange@gmail.com
project = zeta-environs-173316
Comment on lines +2 to +3
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded email and project values should be replaced with variables like {{ gcloud_account }} and {{ gcloud_project }} to make the template configurable.

Suggested change
account = nick.lange@gmail.com
project = zeta-environs-173316
account = {{ gcloud_account }}
project = {{ gcloud_project }}

Copilot uses AI. Check for mistakes.
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# vars file for role-install-gcloud

gcloud_archive_url: "https://dl.google.com/dl/cloudsdk/channels/rapid/downloads"
gcloud_credentials: "our_creds.json"