joelbirchler
2020-03-03 73a52a15ce4aefe711f0dd684cadb5cb2c52602d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
---
- name: Clone private workloads
  hosts: localhost
  gather_facts: false
  run_once: true
  become: false
  pre_tasks:
    - include: workloads_cleanup.yml
  tasks:
    - name: Create and pull repo
      shell: |
        source_path=/tmp/{{ item.name }}-private-workload
        workload_path=$(pwd)/../../roles/{{ item.name }}-private-workload
        
        mkdir -p $source_path && cd $source_path
 
        git init
        git remote add origin {{ item.url }}
 
        git config core.sparseCheckout true
        echo "{{ item.path }}" >> .git/info/sparse-checkout
        git config core.sshCommand "ssh -i {{ item.ssh_key }} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
 
        git pull --depth=1 origin master
 
        ln -s $source_path/{{ item.path }} $workload_path 
      loop: "{{ private_workloads }}"
 
- name: Install workloads
  hosts: bastions
  gather_facts: false
  run_once: true
  become: false
  tasks:
    - name: Include private workloads
      include_role:
        name: "{{ item.name }}-private-workload"
      vars:
        ACTION:         "provision"
        workload_name:  "{{ item.name }}"
        git_ssh_key:    "{{ item.git_ssh_key }}"
      loop: "{{ private_workloads }}"
 
- name: Cleanup private workloads
  hosts: localhost
  gather_facts: false
  run_once: true
  become: false
  tasks:
    - include: workloads_cleanup.yml