From 21f4e17ced0048986b9dd5f8784006b4caa67ca0 Mon Sep 17 00:00:00 2001 From: L. Alberto Giménez Date: Jan 16 2020 11:32:34 +0000 Subject: Allow GCS cache configuration --- diff --git a/defaults/main.yml b/defaults/main.yml index 533e8ca..1c087ae 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -98,6 +98,18 @@ gitlab_runner_runners: # Cache S3 insecure # cache_s3_insecure: false # + # Cache GCS Bucket name + # cache_gcs_bucket_name: "my-bucket" + # + # Cache GCS CredentialsFile + # cache_gcs_credentials_file: "/path/to/key_file.json" + # + # Cache GCS Access ID + # cache_gcs_access_id: "cache-access-account@project.iam.gserviceaccount.com" + # + # Cache GCS Private Key + # cache_gcs_private_key: "-----BEGIN PRIVATE KEY-----\nXXXXXX\n-----END PRIVATE KEY-----\n" + # # Builds directory # builds_dir: '/builds_dir' # diff --git a/tasks/update-config-runner.yml b/tasks/update-config-runner.yml index 795ea97..61523a1 100644 --- a/tasks/update-config-runner.yml +++ b/tasks/update-config-runner.yml @@ -136,6 +136,17 @@ check_mode: no notify: restart_gitlab_runner +- name: Set cache gcs section + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*\[runners\.cache\.gcs\]' + line: ' [runners.cache.gcs]' + state: "{{ 'present' if gitlab_runner.cache_gcs_bucket_name is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + - name: Set cache type option lineinfile: dest: "{{ temp_runner_config.path }}" @@ -238,6 +249,52 @@ notify: restart_gitlab_runner +#### [runners.cache.gcs] section #### +- name: Set cache gcs bucket name + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*BucketName =' + line: ' BucketName = {{ gitlab_runner.cache_gcs_bucket_name|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_bucket_name is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + +- name: Set cache gcs credentials file + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*CredentialsFile =' + line: ' CredentialsFile = {{ gitlab_runner.cache_gcs_credentials_file|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_credentials_file is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + +- name: Set cache gcs access id + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*AccessID =' + line: ' AccessID = {{ gitlab_runner.cache_gcs_access_id|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_access_id is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + +- name: Set cache gcs private key + lineinfile: + dest: "{{ temp_runner_config.path }}" + regexp: '^\s*PrivateKey =' + line: ' PrivateKey = {{ gitlab_runner.cache_gcs_private_key|default("") | to_json }}' + state: "{{ 'present' if gitlab_runner.cache_gcs_private_key is defined else 'absent' }}" + insertafter: '^\s*\[runners\.cache\.gcs\]' + backrefs: no + check_mode: no + notify: restart_gitlab_runner + + #### [runners.ssh] section ##### - name: Set ssh user option lineinfile: