2016-11-03 20:57:33 +08:00
|
|
|
---
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Upload logs to GCS
|
|
|
|
hosts: localhost
|
2016-11-03 20:57:33 +08:00
|
|
|
become: false
|
|
|
|
gather_facts: no
|
|
|
|
|
2016-11-09 21:15:27 +08:00
|
|
|
vars:
|
|
|
|
expire_days: 2
|
|
|
|
|
2016-11-03 20:57:33 +08:00
|
|
|
tasks:
|
2020-07-28 23:39:47 +08:00
|
|
|
- name: Generate uniq bucket name prefix
|
2016-11-16 18:30:00 +08:00
|
|
|
raw: date +%Y%m%d
|
2020-07-28 23:39:47 +08:00
|
|
|
changed_when: false
|
2016-11-07 23:00:49 +08:00
|
|
|
register: out
|
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Replace_test_id
|
2016-11-03 20:57:33 +08:00
|
|
|
set_fact:
|
2016-11-16 18:30:00 +08:00
|
|
|
test_name: "kargo-ci-{{ out.stdout_lines[0] }}"
|
2016-11-09 21:15:27 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Set file_name for logs
|
|
|
|
set_fact:
|
2019-05-03 05:24:21 +08:00
|
|
|
file_name: "{{ ostype }}-{{ kube_network_plugin }}-{{ commit }}-logs.tar.gz"
|
2016-11-03 20:57:33 +08:00
|
|
|
|
|
|
|
- name: Create a bucket
|
2023-06-26 18:15:45 +08:00
|
|
|
community.google.gc_storage:
|
2016-11-03 20:57:33 +08:00
|
|
|
bucket: "{{ test_name }}"
|
|
|
|
mode: create
|
2016-11-09 21:15:27 +08:00
|
|
|
permission: public-read
|
2016-11-07 23:00:49 +08:00
|
|
|
gs_access_key: "{{ gs_key }}"
|
|
|
|
gs_secret_key: "{{ gs_skey }}"
|
|
|
|
no_log: True
|
|
|
|
|
2016-11-09 21:15:27 +08:00
|
|
|
- name: Create a lifecycle template for the bucket
|
|
|
|
template:
|
|
|
|
src: gcs_life.json.j2
|
2019-05-03 05:24:21 +08:00
|
|
|
dest: "{{ dir }}/gcs_life.json"
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0644
|
2016-11-09 21:15:27 +08:00
|
|
|
|
|
|
|
- name: Create a boto config to access GCS
|
|
|
|
template:
|
|
|
|
src: boto.j2
|
2019-05-03 05:24:21 +08:00
|
|
|
dest: "{{ dir }}/.boto"
|
2021-07-12 15:00:47 +08:00
|
|
|
mode: 0640
|
2016-11-09 21:15:27 +08:00
|
|
|
no_log: True
|
|
|
|
|
2016-11-07 23:00:49 +08:00
|
|
|
- name: Download gsutil cp installer
|
|
|
|
get_url:
|
|
|
|
url: https://dl.google.com/dl/cloudsdk/channels/rapid/install_google_cloud_sdk.bash
|
2019-05-03 05:24:21 +08:00
|
|
|
dest: "{{ dir }}/gcp-installer.sh"
|
2023-06-26 18:15:45 +08:00
|
|
|
mode: 0644
|
2016-11-07 23:00:49 +08:00
|
|
|
|
|
|
|
- name: Get gsutil tool
|
2023-06-26 18:15:45 +08:00
|
|
|
command: "{{ dir }}/gcp-installer.sh"
|
2016-11-07 23:00:49 +08:00
|
|
|
environment:
|
2023-06-26 18:15:45 +08:00
|
|
|
CLOUDSDK_CORE_DISABLE_PROMPTS: "1"
|
2019-05-03 05:24:21 +08:00
|
|
|
CLOUDSDK_INSTALL_DIR: "{{ dir }}"
|
2016-11-07 23:00:49 +08:00
|
|
|
no_log: True
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2016-11-07 23:00:49 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- name: Apply the lifecycle rules
|
2019-05-03 05:24:21 +08:00
|
|
|
command: "{{ dir }}/google-cloud-sdk/bin/gsutil lifecycle set {{ dir }}/gcs_life.json gs://{{ test_name }}"
|
2020-09-10 18:45:54 +08:00
|
|
|
changed_when: false
|
2016-11-07 23:00:49 +08:00
|
|
|
environment:
|
2019-05-03 05:24:21 +08:00
|
|
|
BOTO_CONFIG: "{{ dir }}/.boto"
|
2016-11-09 21:15:27 +08:00
|
|
|
no_log: True
|
2016-11-03 20:57:33 +08:00
|
|
|
|
|
|
|
- name: Upload collected diagnostic info
|
2023-06-26 18:15:45 +08:00
|
|
|
community.google.gc_storage:
|
2016-11-03 20:57:33 +08:00
|
|
|
bucket: "{{ test_name }}"
|
|
|
|
mode: put
|
2016-11-09 21:15:27 +08:00
|
|
|
permission: public-read
|
|
|
|
object: "{{ file_name }}"
|
2019-05-03 05:24:21 +08:00
|
|
|
src: "{{ dir }}/logs.tar.gz"
|
2016-11-07 23:00:49 +08:00
|
|
|
headers: '{"Content-Encoding": "x-gzip"}'
|
|
|
|
gs_access_key: "{{ gs_key }}"
|
|
|
|
gs_secret_key: "{{ gs_skey }}"
|
2023-07-05 11:36:54 +08:00
|
|
|
expiration: "{{ expire_days * 36000 | int }}"
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2016-11-09 21:15:27 +08:00
|
|
|
no_log: True
|
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- debug: # noqa name[missing]
|
2019-05-03 05:24:21 +08:00
|
|
|
msg: "A public url https://storage.googleapis.com/{{ test_name }}/{{ file_name }}"
|