mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-07-27 23:21:31 -07:00
gcloud role w/tests
This commit is contained in:
parent
9bfffd56e8
commit
fa14b8c218
23 changed files with 643 additions and 0 deletions
21
roles/gcloud/LICENSE
Normal file
21
roles/gcloud/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Eric Anderson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
60
roles/gcloud/README.md
Normal file
60
roles/gcloud/README.md
Normal file
|
@ -0,0 +1,60 @@
|
|||
# ericsysmin.gcloud
|
||||
|
||||
[](https://travis-ci.org/ericsysmin/ansible-role-gcloud)
|
||||
|
||||
This role installs the gcloud command-line tool on a linux system.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Debian
|
||||
|
||||
None
|
||||
|
||||
### Ubuntu
|
||||
|
||||
None
|
||||
|
||||
### CentOS
|
||||
|
||||
- epel (if using archive installation)
|
||||
|
||||
## Role Variables
|
||||
|
||||
All variables which can be overridden are stored in defaults/main.yml file as well as in table below.
|
||||
|
||||
| Variable | Required | Default | Comments |
|
||||
| ------------------------------ | -------- | -------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
|
||||
| `gcloud_install_type` | No | `package` | Type of install `package` or `archive` |
|
||||
| `gcloud_apt_url` | No | `http://packages.cloud.google.com/apt` | URL of the APT Repository |
|
||||
| `gcloud_apt_key` | No | `https://packages.cloud.google.com/apt/doc/apt-key.gpg` | GPG Key for the APT Repository |
|
||||
| `gcloud_apt_repo` | No | `cloud-sdk-{{ ansible_distribution_release }}` | Name of the APT Repository |
|
||||
| `gcloud_yum_baseurl` | No | `https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64` | URL of the YUM Repository |
|
||||
| `gcloud_yum_key` | No | `https://packages.cloud.google.com/yum/doc/yum-key.gpg` | GPG Key for the YUM Repository |
|
||||
| `gcloud_version` | No | `268.0.0` | Version of google-cloud-sdk to install |
|
||||
| `gcloud_archive_name` | No | `google-cloud-sdk-{{ gcloud_version }}-linux-{{ ansible_architecture }}.tar.gz` | Full length name of gcloud archive |
|
||||
| `gcloud_archive_url` | No | `https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/{{ gcloud_archive_name }}` | URL to download the gcloud archive |
|
||||
| `gcloud_archive_path` | No | `/usr/lib` | Where should we unpack the archive |
|
||||
| `gcloud_library_path` | No | `{{ gcloud_archive_path }}/google-cloud-sdk` | Path of the library after archive unpack |
|
||||
| `gcloud_install_script` | No | `false` | Boolean: Execute install.sh from archive |
|
||||
| `gcloud_usage_reporting` | No | `false` | Boolean: Disable anonymous usage reporting. |
|
||||
| `gcloud_profile_path` | No | `false` | Profile to update with PATH and completion. |
|
||||
| `gcloud_command_completion` | No | `false` | Boolean: Add a line for command completion in the profile |
|
||||
| `gcloud_update_path` | No | `false` | Boolean: Add a line for path updating in the profile |
|
||||
| `gcloud_override_components` | No | `[]` | Override the components that would be installed by default |
|
||||
| `gcloud_additional_components` | No | `[]` | Additional components to installed |
|
||||
|
||||
## Example Playbook
|
||||
|
||||
```yaml
|
||||
- hosts: servers
|
||||
roles:
|
||||
- role: ericsysmin.gcloud
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Author Information
|
||||
|
||||
[ericsysmin](https://ericsysmin.com)
|
28
roles/gcloud/defaults/main.yml
Normal file
28
roles/gcloud/defaults/main.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
# defaults file for gcloud
|
||||
gcloud_install_type: package
|
||||
|
||||
# default values for gcloud apt installation
|
||||
gcloud_apt_key: https://packages.cloud.google.com/apt/doc/apt-key.gpg
|
||||
gcloud_apt_url: http://packages.cloud.google.com/apt
|
||||
gcloud_apt_repo: cloud-sdk-{{ ansible_distribution_release }}
|
||||
|
||||
# default values for gcloud yum installation
|
||||
gcloud_yum_baseurl: https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
|
||||
gcloud_yum_key: https://packages.cloud.google.com/yum/doc/yum-key.gpg
|
||||
|
||||
# default values for gcloud archive installation
|
||||
gcloud_version: 268.0.0
|
||||
gcloud_archive_name: google-cloud-sdk-{{ gcloud_version }}-linux-{{ ansible_architecture }}.tar.gz
|
||||
gcloud_archive_url: https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/{{ gcloud_archive_name }}
|
||||
gcloud_archive_path: /usr/lib
|
||||
gcloud_library_path: "{{ gcloud_archive_path }}/google-cloud-sdk"
|
||||
|
||||
# values if you want to use the gcloud install script
|
||||
gcloud_install_script: false
|
||||
gcloud_usage_reporting: false
|
||||
gcloud_profile_path: false
|
||||
gcloud_command_completion: false
|
||||
gcloud_update_path: false
|
||||
gcloud_override_components: []
|
||||
gcloud_additional_components: []
|
21
roles/gcloud/meta/main.yml
Normal file
21
roles/gcloud/meta/main.yml
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
galaxy_info:
|
||||
role_name: gcloud
|
||||
author: Eric Anderson
|
||||
description: Ansible role to install google-cloud-sdk
|
||||
company: Avi Networks
|
||||
license: MIT
|
||||
min_ansible_version: 2.4
|
||||
platforms:
|
||||
- name: Ubuntu
|
||||
versions:
|
||||
- precise
|
||||
- trusty
|
||||
- xenial
|
||||
- bionic
|
||||
galaxy_tags:
|
||||
- gcloud
|
||||
- google
|
||||
- cloud
|
||||
- sdk
|
||||
dependencies: []
|
50
roles/gcloud/tasks/archive/archive_install.yml
Normal file
50
roles/gcloud/tasks/archive/archive_install.yml
Normal file
|
@ -0,0 +1,50 @@
|
|||
---
|
||||
- name: gcloud | Archive | Ensure temp path exists
|
||||
file: path={{ gcloud_archive_path }} state=directory
|
||||
|
||||
- name: gcloud | Archive | Extract Cloud SDK archive
|
||||
unarchive:
|
||||
src: "{{ gcloud_archive_url }}"
|
||||
dest: "{{ gcloud_archive_path }}"
|
||||
remote_src: yes
|
||||
creates: "{{ gcloud_library_path }}"
|
||||
|
||||
- name: gcloud | Archive | Link binaries to /usr/bin (like package install)
|
||||
file:
|
||||
src: "{{ gcloud_library_path }}/bin/{{ item }}"
|
||||
dest: "/usr/bin/{{ item }}"
|
||||
state: link
|
||||
loop:
|
||||
- bq
|
||||
- docker-credential-gcloud
|
||||
- gcloud
|
||||
- git-credential-gcloud.sh
|
||||
- gsutil
|
||||
when: not gcloud_install_script
|
||||
|
||||
- name: gcloud | Archive | Add command completion
|
||||
include_tasks: command_completion.yml
|
||||
when: gcloud_command_completion
|
||||
|
||||
- name: gcloud | Archive | Install into Path
|
||||
command: >-
|
||||
{{ gcloud_archive_path }}/install.sh --quiet
|
||||
--usage-reporting {{ gcloud_usage_reporting | lower }}
|
||||
{% if gcloud_profile_path %}
|
||||
--rc-path {{ gcloud_profile_path }}
|
||||
{% endif %}
|
||||
--command-completion {{ gcloud_command_completion | lower }}
|
||||
--path-update {{ gcloud_update_path | lower }}
|
||||
{% if gcloud_override_components | length > 0 %}--override-components
|
||||
{% for component in gcloud_override_components %}{{ component }}
|
||||
{% if loop.index < gcloud_override_components | length %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if gcloud_additional_components | length > 0 %}--additional-components
|
||||
{% for component in gcloud_additional_components %}{{ component }}
|
||||
{% if loop.index < gcloud_additional_components | length %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
when: gcloud_install_script
|
32
roles/gcloud/tasks/archive/command_completion.yml
Normal file
32
roles/gcloud/tasks/archive/command_completion.yml
Normal file
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
# task file to configure bash completion for gcloud
|
||||
- name: gcloud | Archive | Debian | Ensure bash completion is installed
|
||||
apt: name=bash-completion
|
||||
register: task_result
|
||||
until: task_result is success
|
||||
retries: 10
|
||||
delay: 2
|
||||
when: ansible_os_family == "Debian"
|
||||
|
||||
- name: gcloud | Archive | RedHat | Ensure bash completion is installed
|
||||
yum:
|
||||
name:
|
||||
- bash-completion
|
||||
register: task_result
|
||||
until: task_result is success
|
||||
retries: 10
|
||||
delay: 2
|
||||
when: ansible_os_family == "RedHat"
|
||||
|
||||
- name: gcloud | Archive | Ensure bash_completion.d directory exists
|
||||
file:
|
||||
path: /etc/bash_completion.d
|
||||
owner: root
|
||||
group: root
|
||||
state: directory
|
||||
|
||||
- name: gcloud | Archive | Link binaries to /usr/bin (like package install)
|
||||
file:
|
||||
src: "{{ gcloud_library_path }}/completion.bash.inc"
|
||||
dest: /etc/bash_completion.d/gcloud
|
||||
state: link
|
37
roles/gcloud/tasks/archive/main.yml
Normal file
37
roles/gcloud/tasks/archive/main.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
# tasks to install gcloud via archive
|
||||
- name: gcloud | Archive | Look for existing Google Cloud SDK installation
|
||||
stat:
|
||||
path: "{{ gcloud_archive_path }}/google-cloud-sdk/VERSION"
|
||||
register: gcloud_status
|
||||
|
||||
- debug: var=gcloud_status
|
||||
|
||||
- name: gcloud | Archive | Set installed version if installation exists
|
||||
block:
|
||||
- name: gcloud | Archive | Importing contents of {{ gcloud_archive_path }}/google-cloud-sdk/VERSION
|
||||
slurp:
|
||||
src: "{{ gcloud_archive_path }}/google-cloud-sdk/VERSION"
|
||||
register: gcloud_installed_version_data
|
||||
- name: gcloud | Archive | Setting the gcloud_installed_version variable/fact
|
||||
set_fact:
|
||||
gcloud_installed_version: "{{ (gcloud_installed_version_data.content|b64decode|trim) }}"
|
||||
- debug:
|
||||
msg: "google-cloud-sdk: {{ gcloud_installed_version }} is installed"
|
||||
- debug:
|
||||
msg: >-
|
||||
Skipping installation of google-cloud-sdk version {{ gcloud_version }} when
|
||||
{{ gcloud_installed_version }} is already installed.
|
||||
when: gcloud_version == gcloud_installed_version
|
||||
when: gcloud_status.stat.exists
|
||||
|
||||
- name: gcloud | Archive | Start installation
|
||||
include_tasks: archive_install.yml
|
||||
when: gcloud_installed_version is undefined or
|
||||
gcloud_version is version(gcloud_installed_version, '>')
|
||||
|
||||
- name: gcloud | Debian | Install the google-cloud-sdk additional components # noqa 301
|
||||
command: gcloud components install {{ item }}
|
||||
register: gcloud_install_comp_status
|
||||
changed_when: "'All components are up to date.' not in gcloud_install_comp_status.stderr_lines"
|
||||
loop: "{{ gcloud_additional_components }}"
|
15
roles/gcloud/tasks/main.yml
Normal file
15
roles/gcloud/tasks/main.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
|
||||
- name: gcloud | Load Distro and OS specific variables
|
||||
include_vars: "{{ lookup('first_found', params) }}"
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- "os/{{ ansible_distribution|lower }}.yml"
|
||||
- "os/{{ ansible_os_family|lower }}.yml"
|
||||
- main.yml
|
||||
paths:
|
||||
- 'vars'
|
||||
|
||||
- name: gcloud | Install the google-cloud-sdk from {{ gcloud_install_type }}
|
||||
include_tasks: "{{ gcloud_install_type }}/main.yml"
|
27
roles/gcloud/tasks/package/debian.yml
Normal file
27
roles/gcloud/tasks/package/debian.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
# tasks that install gcloud on debian
|
||||
- name: gcloud | Debian | Add an Apt signing key, uses whichever key is at the URL
|
||||
apt_key:
|
||||
url: "{{ gcloud_apt_key }}"
|
||||
state: present
|
||||
|
||||
- name: gcloud | Debian | Add the gcloud repository
|
||||
apt_repository:
|
||||
repo: "deb {{ gcloud_apt_url }} {{ gcloud_apt_repo }} main"
|
||||
state: present
|
||||
filename: google-cloud-sdk
|
||||
|
||||
- name: gcloud | Debian | Install the google-cloud-sdk package
|
||||
apt: name=google-cloud-sdk update_cache=yes
|
||||
register: task_result
|
||||
until: task_result is success
|
||||
retries: 10
|
||||
delay: 2
|
||||
|
||||
- name: gcloud | Debian | Install the google-cloud-sdk additional components
|
||||
apt: name=google-cloud-sdk-{{ item }} update_cache=yes
|
||||
register: task_result
|
||||
until: task_result is success
|
||||
retries: 10
|
||||
delay: 2
|
||||
loop: "{{ gcloud_additional_components }}"
|
5
roles/gcloud/tasks/package/main.yml
Normal file
5
roles/gcloud/tasks/package/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
# tasks file for gcloud
|
||||
|
||||
- name: gcloud | Start package installation for specific distro
|
||||
include_tasks: "{{ ansible_os_family|lower }}.yml"
|
28
roles/gcloud/tasks/package/redhat.yml
Normal file
28
roles/gcloud/tasks/package/redhat.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
---
|
||||
- name: gcloud | RHEL | Add an Apt signing key, uses whichever key is at the URL
|
||||
yum_repository:
|
||||
name: google-cloud-sdk
|
||||
description: Google Cloud SDK
|
||||
file: google-cloud-sdk
|
||||
baseurl: https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
|
||||
enabled: yes
|
||||
gpgcheck: yes
|
||||
repo_gpgcheck: yes
|
||||
gpgkey:
|
||||
- https://packages.cloud.google.com/yum/doc/yum-key.gpg
|
||||
- https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
|
||||
|
||||
- name: gcloud | RHEL | Install the google-cloud-sdk package
|
||||
yum: name=google-cloud-sdk update_cache=yes
|
||||
register: task_result
|
||||
until: task_result is success
|
||||
retries: 10
|
||||
delay: 2
|
||||
|
||||
- name: gcloud | Debian | Install the google-cloud-sdk additional components
|
||||
yum: name=google-cloud-sdk-{{ item }} update_cache=yes
|
||||
register: task_result
|
||||
until: task_result is success
|
||||
retries: 10
|
||||
delay: 2
|
||||
loop: "{{ gcloud_additional_components }}"
|
1
roles/gcloud/vars/main.yml
Normal file
1
roles/gcloud/vars/main.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
Loading…
Add table
Add a link
Reference in a new issue