install.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. ---
  2. # Fact setting and validations
  3. - name: Set default image variables based on deployment type
  4. include_vars: "{{ item }}"
  5. with_first_found:
  6. - "{{ openshift_deployment_type | default(deployment_type) }}.yml"
  7. - "default_images.yml"
  8. - name: set ansible_service_broker facts
  9. set_fact:
  10. ansible_service_broker_image_prefix: "{{ ansible_service_broker_image_prefix | default(__ansible_service_broker_image_prefix) }}"
  11. ansible_service_broker_image_tag: "{{ ansible_service_broker_image_tag | default(__ansible_service_broker_image_tag) }}"
  12. ansible_service_broker_etcd_image_prefix: "{{ ansible_service_broker_etcd_image_prefix | default(__ansible_service_broker_etcd_image_prefix) }}"
  13. ansible_service_broker_etcd_image_tag: "{{ ansible_service_broker_etcd_image_tag | default(__ansible_service_broker_etcd_image_tag) }}"
  14. ansible_service_broker_etcd_image_etcd_path: "{{ ansible_service_broker_etcd_image_etcd_path | default(__ansible_service_broker_etcd_image_etcd_path) }}"
  15. ansible_service_broker_registry_type: "{{ ansible_service_broker_registry_type | default(__ansible_service_broker_registry_type) }}"
  16. ansible_service_broker_registry_name: "{{ ansible_service_broker_registry_name | default(__ansible_service_broker_registry_name) }}"
  17. ansible_service_broker_registry_url: "{{ ansible_service_broker_registry_url | default(__ansible_service_broker_registry_url) }}"
  18. ansible_service_broker_registry_user: "{{ ansible_service_broker_registry_user | default(__ansible_service_broker_registry_user) }}"
  19. ansible_service_broker_registry_password: "{{ ansible_service_broker_registry_password | default(__ansible_service_broker_registry_password) }}"
  20. ansible_service_broker_registry_organization: "{{ ansible_service_broker_registry_organization | default(__ansible_service_broker_registry_organization) }}"
  21. ansible_service_broker_registry_tag: "{{ ansible_service_broker_registry_tag | default(__ansible_service_broker_registry_tag) }}"
  22. ansible_service_broker_registry_whitelist: "{{ ansible_service_broker_registry_whitelist | default(__ansible_service_broker_registry_whitelist) }}"
  23. - name: set ansible-service-broker image facts using set prefix and tag
  24. set_fact:
  25. ansible_service_broker_image: "{{ ansible_service_broker_image_prefix }}ansible-service-broker:{{ ansible_service_broker_image_tag }}"
  26. ansible_service_broker_etcd_image: "{{ ansible_service_broker_etcd_image_prefix }}etcd:{{ ansible_service_broker_etcd_image_tag }}"
  27. - include: validate_facts.yml
  28. # Deployment of ansible-service-broker starts here
  29. - name: create openshift-ansible-service-broker project
  30. oc_project:
  31. name: openshift-ansible-service-broker
  32. state: present
  33. - name: create ansible-service-broker serviceaccount
  34. oc_serviceaccount:
  35. name: asb
  36. namespace: openshift-ansible-service-broker
  37. state: present
  38. - name: create ansible-service-broker client serviceaccount
  39. oc_serviceaccount:
  40. name: asb-client
  41. namespace: openshift-ansible-service-broker
  42. state: present
  43. - name: Create asb-auth cluster role
  44. oc_clusterrole:
  45. state: present
  46. name: asb-auth
  47. rules:
  48. - apiGroups: [""]
  49. resources: ["namespaces"]
  50. verbs: ["create", "delete"]
  51. - apiGroups: ["authorization.openshift.io"]
  52. resources: ["subjectrulesreview"]
  53. verbs: ["create"]
  54. - apiGroups: ["authorization.k8s.io"]
  55. resources: ["subjectaccessreviews"]
  56. verbs: ["create"]
  57. - apiGroups: ["authentication.k8s.io"]
  58. resources: ["tokenreviews"]
  59. verbs: ["create"]
  60. - name: Create asb-access cluster role
  61. oc_clusterrole:
  62. state: present
  63. name: asb-access
  64. rules:
  65. - nonResourceURLs: ["/ansible-service-broker", "/ansible-service-broker/*"]
  66. verbs: ["get", "post", "put", "patch", "delete"]
  67. - name: Bind admin cluster-role to asb serviceaccount
  68. oc_adm_policy_user:
  69. state: present
  70. resource_kind: cluster-role
  71. resource_name: admin
  72. user: "system:serviceaccount:openshift-ansible-service-broker:asb"
  73. - name: Bind auth cluster role to asb service account
  74. oc_adm_policy_user:
  75. state: present
  76. resource_kind: cluster-role
  77. resource_name: asb-auth
  78. user: "system:serviceaccount:openshift-ansible-service-broker:asb"
  79. - name: Bind asb-access role to asb-client service account
  80. oc_adm_policy_user:
  81. state: present
  82. resource_kind: cluster-role
  83. resource_name: asb-access
  84. user: "system:serviceaccount:openshift-ansible-service-broker:asb-client"
  85. - name: create asb-client token secret
  86. oc_obj:
  87. name: asb-client
  88. namespace: openshift-ansible-service-broker
  89. state: present
  90. kind: Secret
  91. content:
  92. path: /tmp/asbclientsecretout
  93. data:
  94. apiVersion: v1
  95. kind: Secret
  96. metadata:
  97. name: asb-client
  98. namespace: openshift-ansible-service-broker
  99. annotations:
  100. kubernetes.io/service-account.name: asb-client
  101. type: kubernetes.io/service-account-token
  102. - oc_secret:
  103. state: list
  104. namespace: openshift-ansible-service-broker
  105. name: asb-client
  106. register: asb_client_secret
  107. - set_fact:
  108. service_ca_crt: "{{ asb_client_secret.results.results.0.data['service-ca.crt'] }}"
  109. # Using oc_obj because oc_service doesn't seem to allow annotations
  110. # TODO: Extend oc_service to allow annotations
  111. - name: create ansible-service-broker service
  112. oc_obj:
  113. name: asb
  114. namespace: openshift-ansible-service-broker
  115. state: present
  116. kind: Service
  117. content:
  118. path: /tmp/asbsvcout
  119. data:
  120. apiVersion: v1
  121. kind: Service
  122. metadata:
  123. name: asb
  124. namespace: openshift-ansible-service-broker
  125. labels:
  126. app: openshift-ansible-service-broker
  127. service: asb
  128. annotations:
  129. service.alpha.openshift.io/serving-cert-secret-name: asb-tls
  130. spec:
  131. ports:
  132. - name: port-1338
  133. port: 1338
  134. targetPort: 1338
  135. protocol: TCP
  136. selector:
  137. app: openshift-ansible-service-broker
  138. service: asb
  139. - name: create route for ansible-service-broker service
  140. oc_route:
  141. name: asb-1338
  142. namespace: openshift-ansible-service-broker
  143. state: present
  144. labels:
  145. app: openshift-ansible-service-broker
  146. service: asb
  147. service_name: asb
  148. port: 1338
  149. tls_termination: Reencrypt
  150. - name: create persistent volume claim for etcd
  151. oc_obj:
  152. name: etcd
  153. namespace: openshift-ansible-service-broker
  154. state: present
  155. kind: PersistentVolumeClaim
  156. content:
  157. path: /tmp/pvcout
  158. data:
  159. apiVersion: v1
  160. kind: PersistentVolumeClaim
  161. metadata:
  162. name: etcd
  163. namespace: openshift-ansible-service-broker
  164. spec:
  165. accessModes:
  166. - ReadWriteOnce
  167. resources:
  168. requests:
  169. storage: 1Gi
  170. - name: Create Ansible Service Broker deployment config
  171. oc_obj:
  172. name: asb
  173. namespace: openshift-ansible-service-broker
  174. state: present
  175. kind: DeploymentConfig
  176. content:
  177. path: /tmp/dcout
  178. data:
  179. apiVersion: v1
  180. kind: DeploymentConfig
  181. metadata:
  182. name: asb
  183. labels:
  184. app: openshift-ansible-service-broker
  185. service: asb
  186. spec:
  187. replicas: 1
  188. selector:
  189. app: openshift-ansible-service-broker
  190. strategy:
  191. type: Rolling
  192. template:
  193. metadata:
  194. labels:
  195. app: openshift-ansible-service-broker
  196. service: asb
  197. spec:
  198. serviceAccount: asb
  199. containers:
  200. - image: "{{ ansible_service_broker_image }}"
  201. name: asb
  202. imagePullPolicy: IfNotPresent
  203. volumeMounts:
  204. - name: config-volume
  205. mountPath: /etc/ansible-service-broker
  206. - name: asb-tls
  207. mountPath: /etc/tls/private
  208. ports:
  209. - containerPort: 1338
  210. protocol: TCP
  211. env:
  212. - name: BROKER_CONFIG
  213. value: /etc/ansible-service-broker/config.yaml
  214. resources: {}
  215. terminationMessagePath: /tmp/termination-log
  216. readinessProbe:
  217. httpGet:
  218. port: 1338
  219. path: /healthz
  220. scheme: HTTPS
  221. initialDelaySeconds: 15
  222. timeoutSeconds: 1
  223. livenessProbe:
  224. httpGet:
  225. port: 1338
  226. path: /healthz
  227. scheme: HTTPS
  228. initialDelaySeconds: 15
  229. timeoutSeconds: 1
  230. - image: "{{ ansible_service_broker_etcd_image }}"
  231. name: etcd
  232. imagePullPolicy: IfNotPresent
  233. terminationMessagePath: /tmp/termination-log
  234. workingDir: /etcd
  235. args:
  236. - "{{ ansible_service_broker_etcd_image_etcd_path }}"
  237. - "--data-dir=/data"
  238. - "--listen-client-urls=http://0.0.0.0:2379"
  239. - "--advertise-client-urls=http://0.0.0.0:2379"
  240. ports:
  241. - containerPort: 2379
  242. protocol: TCP
  243. env:
  244. - name: ETCDCTL_API
  245. value: "3"
  246. volumeMounts:
  247. - mountPath: /data
  248. name: etcd
  249. volumes:
  250. - name: etcd
  251. persistentVolumeClaim:
  252. claimName: etcd
  253. - name: config-volume
  254. configMap:
  255. name: broker-config
  256. items:
  257. - key: broker-config
  258. path: config.yaml
  259. - name: asb-tls
  260. secret:
  261. secretName: asb-tls
  262. # TODO: saw a oc_configmap in the library, but didn't understand how to get it to do the following:
  263. - name: Create config map for ansible-service-broker
  264. oc_obj:
  265. name: broker-config
  266. namespace: openshift-ansible-service-broker
  267. state: present
  268. kind: ConfigMap
  269. content:
  270. path: /tmp/cmout
  271. data:
  272. apiVersion: v1
  273. kind: ConfigMap
  274. metadata:
  275. name: broker-config
  276. namespace: openshift-ansible-service-broker
  277. labels:
  278. app: openshift-ansible-service-broker
  279. data:
  280. broker-config: |
  281. registry:
  282. - type: {{ ansible_service_broker_registry_type }}
  283. name: {{ ansible_service_broker_registry_name }}
  284. url: {{ ansible_service_broker_registry_url }}
  285. user: {{ ansible_service_broker_registry_user }}
  286. pass: {{ ansible_service_broker_registry_password }}
  287. org: {{ ansible_service_broker_registry_organization }}
  288. tag: {{ ansible_service_broker_registry_tag }}
  289. white_list: {{ ansible_service_broker_registry_whitelist }}
  290. - type: local_registry
  291. namespaces: ['openshift']
  292. white_list: {{ ansible_service_broker_local_registry_whitelist }}
  293. dao:
  294. etcd_host: 0.0.0.0
  295. etcd_port: 2379
  296. log:
  297. logfile: /var/log/ansible-service-broker/asb.log
  298. stdout: true
  299. level: {{ ansible_service_broker_log_level }}
  300. color: true
  301. openshift:
  302. host: ""
  303. ca_file: ""
  304. bearer_token_file: ""
  305. sandbox_role: {{ ansible_service_broker_sandbox_role }}
  306. image_pull_policy: {{ ansible_service_broker_image_pull_policy }}
  307. broker:
  308. dev_broker: {{ ansible_service_broker_dev_broker | bool | lower }}
  309. bootstrap_on_startup: {{ ansible_service_broker_bootstrap_on_startup | bool | lower }}
  310. refresh_interval: {{ ansible_service_broker_refresh_interval }}
  311. launch_apb_on_bind: {{ ansible_service_broker_launch_apb_on_bind | bool | lower }}
  312. output_request: {{ ansible_service_broker_output_request | bool | lower }}
  313. recovery: {{ ansible_service_broker_recovery | bool | lower }}
  314. ssl_cert_key: /etc/tls/private/tls.key
  315. ssl_cert: /etc/tls/private/tls.crt
  316. auto_escalate: {{ ansible_service_broker_auto_escalate }}
  317. auth:
  318. - type: basic
  319. enabled: false
  320. - name: Create the Broker resource in the catalog
  321. oc_obj:
  322. name: ansible-service-broker
  323. state: present
  324. kind: ClusterServiceBroker
  325. content:
  326. path: /tmp/brokerout
  327. data:
  328. apiVersion: servicecatalog.k8s.io/v1beta1
  329. kind: ClusterServiceBroker
  330. metadata:
  331. name: ansible-service-broker
  332. spec:
  333. url: https://asb.openshift-ansible-service-broker.svc:1338/ansible-service-broker
  334. authInfo:
  335. bearer:
  336. secretRef:
  337. name: asb-client
  338. namespace: openshift-ansible-service-broker
  339. kind: Secret
  340. caBundle: "{{ service_ca_crt }}"