From c7cd5dff0f75dc49e941fad2867483312c8fe55b Mon Sep 17 00:00:00 2001 From: Nick Lange Date: Mon, 14 Sep 2020 09:26:43 -0400 Subject: [PATCH 1/3] Catch up commit - not sure this is a good change --- defaults/main.yml | 17 ++++---- tasks/main.yml | 108 +++++++++++++++++++++++----------------------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 0d3d731..8260973 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,23 +1,22 @@ --- # 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-257.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_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_override_components: [] # Override the components that would be installed by default, and install these instead. +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 diff --git a/tasks/main.yml b/tasks/main.yml index c19f1be..6abfc4e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,65 +1,65 @@ --- -- name: Insure temp path exists - file: - path: "{{ gcloud_tmp_path }}" - state: directory + - block: + - 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 + # + # 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 }}" - when: gcloud_archive_path + # + # 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 - when: gcloud_archive_name + - 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 }}" - when: gcloud_archive_name + - set_fact: + archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_name }}" -- set_fact: - archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_path | basename }}" - when: gcloud_archive_path + - set_fact: + archive_path: "{{ gcloud_tmp_path + '/' + gcloud_archive_path | basename }}" -- name: Unarchive - shell: cd "{{ gcloud_install_path }}" && tar xvzf "{{ archive_path }}" - when: gcloud_archive_name + - 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: 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: Install + command: "{{ gcloud_tmp_path }}/run_install.sh" -- name: Remove the archive - file: - path: "{{ archive_path }}" - state: absent + - 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: Remove the script + file: + path: "{{ gcloud_tmp_path }}/run_install.sh" + state: absent + when: not gcloud_debug + + when: gcloud_archive_name is defined From 86a080bef8991b74d9ed803968b6997188384d39 Mon Sep 17 00:00:00 2001 From: Nick Lange Date: Sun, 19 Nov 2023 17:32:57 -0500 Subject: [PATCH 2/3] November Catchup Commit --- .gitignore | 1 + defaults/main.yml | 2 +- tasks/main.yml | 23 ++++++++++++++++++++++- templates/default_config.j2 | 3 +++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 templates/default_config.j2 diff --git a/.gitignore b/.gitignore index 72364f9..4202365 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ var/ *.egg-info/ .installed.cfg *.egg +*.db # PyInstaller # Usually these files are written by a python script from a template diff --git a/defaults/main.yml b/defaults/main.yml index 8260973..5374871 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,7 @@ --- # defaults file for role-install-gcloud -gcloud_archive_name: 'google-cloud-sdk-257.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. +gcloud_archive_name: 'google-cloud-sdk-455.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. diff --git a/tasks/main.yml b/tasks/main.yml index 6abfc4e..9dc86d1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -13,7 +13,7 @@ url: "{{ gcloud_archive_url }}/{{ gcloud_archive_name }}" dest: "{{ gcloud_tmp_path }}/{{ gcloud_archive_name }}" force: "{{ gcloud_force_download }}" - - set_fact: + - set_fact: gcloud_archive_path: "{{ gcloud_tmp_path }}/{{ gcloud_archive_name }}" # @@ -51,6 +51,27 @@ - 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 }}" diff --git a/templates/default_config.j2 b/templates/default_config.j2 new file mode 100644 index 0000000..9193ba7 --- /dev/null +++ b/templates/default_config.j2 @@ -0,0 +1,3 @@ +[core] +account = nick.lange@gmail.com +project = zeta-environs-173316 From 1779aa978a9692aee08505341c2cb6e6bd8497c0 Mon Sep 17 00:00:00 2001 From: Nick Lange Date: Mon, 1 Sep 2025 22:27:16 -0400 Subject: [PATCH 3/3] Updates to installer for a better experience of setting up nodes --- defaults/main.yml | 7 ++- files | 1 + tasks/authenticate.yml | 18 ++++++ tasks/main.yml | 139 +++++++++++++++++------------------------ tasks/raw_install.yml | 86 +++++++++++++++++++++++++ vars/main.yml | 1 + 6 files changed, 168 insertions(+), 84 deletions(-) create mode 120000 files create mode 100644 tasks/authenticate.yml create mode 100644 tasks/raw_install.yml diff --git a/defaults/main.yml b/defaults/main.yml index 5374871..39e93d8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,7 @@ --- # defaults file for role-install-gcloud -gcloud_archive_name: 'google-cloud-sdk-455.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. +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. @@ -20,3 +20,8 @@ gcloud_override_components: [] # Override the components that would be instal 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 diff --git a/files b/files new file mode 120000 index 0000000..f9fe449 --- /dev/null +++ b/files @@ -0,0 +1 @@ +../../mkrasberry_config/roles/role-install-gcloud/files/ \ No newline at end of file diff --git a/tasks/authenticate.yml b/tasks/authenticate.yml new file mode 100644 index 0000000..75665b9 --- /dev/null +++ b/tasks/authenticate.yml @@ -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 }}" + 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 + \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 9dc86d1..be537ce 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,86 +1,59 @@ --- - - block: - - name: Insure temp path exists - file: - path: "{{ gcloud_tmp_path }}" +- 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 - - # - # 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 - # + mode: "0700" - 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 + 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 }}" + 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 + diff --git a/tasks/raw_install.yml b/tasks/raw_install.yml new file mode 100644 index 0000000..9dc86d1 --- /dev/null +++ b/tasks/raw_install.yml @@ -0,0 +1,86 @@ +--- + - block: + - 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 }}" + - 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 diff --git a/vars/main.yml b/vars/main.yml index 33892c1..72d1406 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -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"