-
Notifications
You must be signed in to change notification settings - Fork 0
/
130.1_playbook_rbac_add_k8s_to_ppdm.yaml
173 lines (167 loc) · 5.49 KB
/
130.1_playbook_rbac_add_k8s_to_ppdm.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# This example Playbook adds a Kubernetes Cluster to PPDM
# Kubernetes Information will be read from k8s core cluster_info module
# it is expected that Environment Variables are set for core K8S Modules
# e.g. export K8S_AUTH_KUBECONFIG=
- name: Add K8S to PPDM
hosts: localhost
gather_facts: no
connection: local
vars_files:
- ./vars/main.yml
collections:
- kubernetes.core
vars:
tasks:
- name: Checking Required Variable ppdm_fqdn
fail:
msg: "We do not have ppdm_fqdn set !"
when: (ppdm_fqdn is not defined) or (ppdm_fqdn|length <= 8)
- name: Checking Required Variables
fail:
msg: "We do not have ppdm_new_password set !"
when: (ppdm_new_password is not defined) or (ppdm_new_password|length == 0)
- name: Setting Base URL
ansible.builtin.set_fact:
ppdm_baseurl: "https://{{ ppdm_fqdn | regex_replace('^https://') }}"
- name: Get Cluster information
kubernetes.core.k8s_cluster_info:
# verify_ssl: no
register: api_status
- debug:
msg: "Connected to {{ api_status.connection.host }}"
verbosity: 0
- name: Setting Connection Parameters from api api_status
set_fact:
k8s_fqdn: "{{ api_status.connection.host | regex_replace('^https://') | regex_replace('\\:\\d+') }}"
k8s_port: "{{ api_status.connection.host.split(':').2 | default('443')}}"
k8s_name: "{{ api_status.connection.host.split('.').1 }}"
- name: apply PPDM RBAC from {{ rbac_source }}
k8s:
verify_ssl: no
state: present
src: "{{ rbac_source }}/ppdm-controller-rbac.yaml"
- name: apply PPDM discovery from {{ rbac_source }}
k8s:
verify_ssl: no
state: present
src: "{{ rbac_source }}/ppdm-discovery.yaml"
- name: apply ppdm-discovery-serviceaccount-token
# we will run this at least 2 Times as the .data.token is not in the result output on 1st
# apply
kubernetes.core.k8s:
verify_ssl: no
state: present
definition:
apiVersion: v1
kind: Secret
metadata:
name: ppdm-discovery-serviceaccount-token
namespace: powerprotect
annotations:
kubernetes.io/service-account.name: ppdm-discovery-serviceaccount
type: kubernetes.io/service-account-token
register: token
retries: "4"
delay: "2"
until: token.result.data.token is defined
- debug:
msg: "{{ token.result.data.token | b64decode }}"
verbosity: 1
- name: register token
ansible.builtin.set_fact:
k8s_token: "{{ token.result.data.token | b64decode }}"
- debug:
msg: "{{ k8s_fqdn }} {{ k8s_name }} {{ k8s_port }}"
verbosity: 1
- name: Get PPDM Token for https://{{ ppdm_fqdn | regex_replace('^https://') }}
include_role:
name: get_ppdm_token
vars:
ppdm_password: "{{ ppdm_new_password }}"
- debug:
msg: "{{ access_token }}"
verbosity: 1
name: do we have a token ?
# - name: enable Kubernetes Asset Source
# include_role:
# name: set_ppdm_asset_setting
# vars:
# data:
# id: ASSET_SETTING
# properties:
# - name: enabledAssetTypes
# type: LIST
# value: KUBERNETES
- name: Get Kubernetes Host Certificate for {{ k8s_fqdn }}
include_role:
name: get_ppdm_host_certificate
vars:
host: "{{ k8s_fqdn }}"
port: "{{ k8s_port }}"
- name: Accept K8S Host Certificate
include_role:
name: accept_ppdm_host_certificate
vars:
old_certificate: "{{ certificate }}"
- name: "Ensure K8S Credentials ppdm-discovery-{{ k8s_fqdn }}"
vars:
data:
method: "TOKEN"
name: "ppdm-discovery-{{ k8s_fqdn }}"
type: "KUBERNETES"
password: "{{ k8s_token }}"
username: "ppdm-discovery-{{ k8s_fqdn }}"
include_role:
name: create_ppdm_credentials
- name: "Get PPDM inventory-sources for {{ vcenter_address }}"
include_role:
name: get_ppdm_inventory-sources
vars:
filter: 'address eq "{{ vcenter_address }}" and type eq "VCENTER"'
when: vcenter_address is defined
- name: inventorysources Result summary
debug:
msg: "{{ inventorysources | json_query('[0].{name: name,id: id,type: type}') }}"
verbosity: 0
when: inventorysources is defined
- name: Setting vCenter Details
set_fact:
details:
k8s:
distributionType: VANILLA_ON_VSPHERE
vCenterId: "{{ inventorysources[0].id }}"
when: inventorysources is defined and vcenter_address is defined
- name: Ensure K8S Cluster {{ k8s_fqdn }} in Inventory with vCenter Details ( CSI Drivers as a Process )
when: details is defined
vars:
data:
name: "{{ k8s_fqdn }}"
type: KUBERNETES
vendor: KUBERNETES
address: "{{ k8s_fqdn }}"
port: "{{ k8s_port | int }}"
details: "{{ details }}"
credentials:
id: "{{ credentials.id }}"
retries: 2
delay: 30
include_role:
name: add_ppdm_inventory
- name: Ensure K8S Cluster {{ k8s_fqdn }} in Inventory without Details
when: details is not defined
vars:
data:
name: "{{ k8s_fqdn }}"
type: KUBERNETES
vendor: KUBERNETES
address: "{{ k8s_fqdn }}"
port: "{{ k8s_port | int }}"
credentials:
id: "{{ credentials.id }}"
retries: 2
delay: 30
include_role:
name: add_ppdm_inventory
- debug:
msg: "{{ inventory }}"
verbosity: 0