-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy_velero.yaml
115 lines (111 loc) · 4.02 KB
/
deploy_velero.yaml
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
- name: Chek if CLI is already installed
tags:
- check
hosts: init
become: true
environment:
PATH: "{{ ansible_env.PATH }}:/var/lib/snapd/snap/bin"
LD_LIBRARY_PATH: "{{ ansible_env.LD_LIBRARY_PATH | default('') }}:/lib64"
tasks:
- name: Ensure ~/.kube dir is present
file:
path: ~/.kube
state: directory
- name: Ensure ~/.kube/config is present
shell: microk8s config > ~/.kube/config
- name: Try to get velero version
command: /usr/local/bin/velero version
register: velero_version_result
ignore_errors: yes
- name: Show velero version result
debug:
var: velero_version_result
- name: Set VELERO_IS_INSTALLED fact
set_fact:
VELERO_IS_INSTALLED: "{{not velero_version_result.failed}}"
- name: Ensure CLI binary is installed
tags:
- install_cli
hosts: init
become: true
tasks:
- name: Is velero already installed?
debug:
msg: "{{VELERO_IS_INSTALLED | default(false)}}"
- name: Ensure download directory is present
file:
path: ~/downloads
state: directory
- name: Download CLI binary
unarchive:
src: https://github.com/vmware-tanzu/velero/releases/download/{{cli.version | default("v1.7.0")}}/velero-{{cli.version | default("v1.7.0")}}-linux-{{cli.arch | default("amd64")}}.tar.gz
dest: ~/downloads/
remote_src: yes
when: VELERO_IS_INSTALLED | default(false)| bool is false
- name: Install CLI binary
copy:
src: ~/downloads/velero-{{cli.version | default("v1.7.0")}}-linux-{{cli.arch | default("amd64")}}/velero
dest: /usr/local/bin/velero
mode: '755'
remote_src: yes
when: VELERO_IS_INSTALLED | default(false)| bool is false
- name: Try to get velero version
command: /usr/local/bin/velero version
register: velero_version_result
when: VELERO_IS_INSTALLED | default(false)| bool is false
- name: Show velero version result
debug:
var: velero_version_result
when: VELERO_IS_INSTALLED | default(false)| bool is false
- name: Setup helm repo
tags:
- prepare
hosts: init
become: true
gather_facts: False
environment:
PATH: "{{ ansible_env.PATH }}:/var/lib/snapd/snap/bin"
LD_LIBRARY_PATH: "{{ ansible_env.LD_LIBRARY_PATH | default('') }}:/lib64"
tasks:
- name: Ensure vmware-tanzu helm repo is added
command: microk8s helm3 repo add vmware-tanzu https://vmware-tanzu.github.io/helm-charts
register: repo_add_result
- name: Show repo add resul
debug:
var: repo_add_result
- name: Install chart
tags:
- install_chart
hosts: init
become: true
gather_facts: False
environment:
PATH: "{{ ansible_env.PATH }}:/var/lib/snapd/snap/bin"
LD_LIBRARY_PATH: "{{ ansible_env.LD_LIBRARY_PATH | default('') }}:/lib64"
tasks:
- name: Ensure vmware-tanzu helm repo is up to date
command: microk8s helm3 repo update
register: repo_update_result
- name: Show repo update result
debug:
var: repo_update_result
- name: Template values.yaml
template:
src: helm_values/velero.yaml.tmpl
dest: "~/helm_values/velero.yaml"
- name: Ensure chart is installed
command: microk8s helm3 upgrade -i -f ~/helm_values/velero.yaml velero vmware-tanzu/velero --namespace {{namespace | default('velero')}} --create-namespace
register: helm_install_result
- name: Show helm install result
debug:
var: helm_install_result
- name: Register existence of restic repositories
command: microk8s kubectl -n velero get resticrepositories.velero.io -o name
register: get_resticrepositories_result
- name: Show Register existence of restic repositories result
debug:
var: get_resticrepositories_result.stdout_lines
- name: Set Restic RepositoryPassword
shell: "microk8s kubectl -n {{namespace | default('velero')}} create secret generic velero-restic-credentials --from-literal=repository-password={{restic.repositoryPassword}} --dry-run -o yaml | microk8s kubectl apply -f - "
when: restic.repositoryPassword is defined and get_resticrepositories_result.stdout_lines | length == 0