Commit d1cefcc3 authored by Jürgen Haas's avatar Jürgen Haas

Finalize Google Cloud for multiple accounts

parent 1118cdd5
......@@ -3,14 +3,14 @@
- name: "Copy Auth File"
copy:
src='{{ inventory_dir }}/files/gcloud/{{ item.authfile }}'
dest='/tmp/{{ item.authfile }}'
src='{{ inventory_dir }}/files/gcloud/{{ gcloud[item].authfile }}'
dest='/tmp/{{ gcloud[item].authfile }}'
- name: "Configure authenticatron"
command: gcloud auth activate-service-account --key-file=/tmp/{{ item.authfile }}
command: gcloud auth activate-service-account --key-file=/tmp/{{ gcloud[item].authfile }}
- name: "Configure project"
command: gcloud config set core/project {{ item.projectid }}
command: gcloud config set core/project {{ gcloud[item].projectid }}
- name: "Configure account"
command: gcloud config set account {{ item.account }}
command: gcloud config set account {{ gcloud[item].account }}
......@@ -16,17 +16,25 @@
- name: "Check available accounts"
command: gcloud auth list
register: gcloud_available_accounts
changed_when: false
- include: config.yml
with_items: '{{ gcloud }}'
when: item.account is not in gcloud_available_accounts.stdout
when: gcloud[item].account not in gcloud_available_accounts.stdout
- name: "Ensure log directory"
file:
path='/var/log/gcloud'
state='directory'
# TODO: The sync items need to define the gcloud account and we have to switch the account before calling rsync
- name: "Copy Sync Script"
template:
src='gcloud-sync.sh'
dest='/usr/local/bin/gcloud-sync.sh'
owner='root'
group='root'
mode='755'
- name: "Crontabs for Google Cloud Sync"
cron:
name='GCloud sync {{ item.source }}'
......@@ -35,7 +43,7 @@
weekday={{ item.weekday|default(omit) }}
hour={{ item.hour|default('1') }}
minute={{ item.minute|default('0') }}
job='gsutil -m rsync -e -r {{ item.source }} gs://{{ item.bucket }}/ >>/var/log/gcloud/rsync.log 2>&1'
job='gcloud-sync.sh {{ gcloud[item.account]["account"] }} {{ gcloud[item.account]["projectid"] }} "{{ item.source }}" "{{ item.bucket }}" >>/var/log/gcloud/rsync.log 2>&1'
with_items: '{{ gcloud_sync|default([]) }}'
tags: 'cron'
......
#!/usr/bin/env bash
gcloud config set account $1
gcloud config set core/project $2
gsutil -m rsync -e -r $3 gs://$4/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment