install.yml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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_tasks: validate_facts.yml
  28. - include_tasks: generate_certs.yml
  29. # Deployment of ansible-service-broker starts here
  30. - name: create openshift-ansible-service-broker project
  31. oc_project:
  32. name: openshift-ansible-service-broker
  33. state: present
  34. - name: create ansible-service-broker serviceaccount
  35. oc_serviceaccount:
  36. name: asb
  37. namespace: openshift-ansible-service-broker
  38. state: present
  39. - name: create ansible-service-broker client serviceaccount
  40. oc_serviceaccount:
  41. name: asb-client
  42. namespace: openshift-ansible-service-broker
  43. state: present
  44. - name: Create asb-auth cluster role
  45. oc_clusterrole:
  46. state: present
  47. name: asb-auth
  48. rules:
  49. - apiGroups: [""]
  50. resources: ["namespaces"]
  51. verbs: ["create", "delete"]
  52. - apiGroups: ["authorization.openshift.io"]
  53. resources: ["subjectrulesreview"]
  54. verbs: ["create"]
  55. - apiGroups: ["authorization.k8s.io"]
  56. resources: ["subjectaccessreviews"]
  57. verbs: ["create"]
  58. - apiGroups: ["authentication.k8s.io"]
  59. resources: ["tokenreviews"]
  60. verbs: ["create"]
  61. - apiGroups: ["image.openshift.io", ""]
  62. resources: ["images"]
  63. verbs: ["get", "list"]
  64. - name: Create asb-access cluster role
  65. oc_clusterrole:
  66. state: present
  67. name: asb-access
  68. rules:
  69. - nonResourceURLs: ["/ansible-service-broker", "/ansible-service-broker/*"]
  70. verbs: ["get", "post", "put", "patch", "delete"]
  71. - name: Bind admin cluster-role to asb serviceaccount
  72. oc_adm_policy_user:
  73. state: present
  74. resource_kind: cluster-role
  75. resource_name: admin
  76. user: "system:serviceaccount:openshift-ansible-service-broker:asb"
  77. - name: Bind auth cluster role to asb service account
  78. oc_adm_policy_user:
  79. state: present
  80. resource_kind: cluster-role
  81. resource_name: asb-auth
  82. user: "system:serviceaccount:openshift-ansible-service-broker:asb"
  83. - name: Bind asb-access role to asb-client service account
  84. oc_adm_policy_user:
  85. state: present
  86. resource_kind: cluster-role
  87. resource_name: asb-access
  88. user: "system:serviceaccount:openshift-ansible-service-broker:asb-client"
  89. - name: create asb-client token secret
  90. oc_obj:
  91. name: asb-client
  92. namespace: openshift-ansible-service-broker
  93. state: present
  94. kind: Secret
  95. content:
  96. path: /tmp/asbclientsecretout
  97. data:
  98. apiVersion: v1
  99. kind: Secret
  100. metadata:
  101. name: asb-client
  102. namespace: openshift-ansible-service-broker
  103. annotations:
  104. kubernetes.io/service-account.name: asb-client
  105. type: kubernetes.io/service-account-token
  106. - name: Create etcd-auth secret
  107. oc_secret:
  108. name: etcd-auth-secret
  109. namespace: openshift-ansible-service-broker
  110. contents:
  111. - path: ca.crt
  112. data: '{{ etcd_ca_cert }}'
  113. - name: Create broker-etcd-auth secret
  114. oc_secret:
  115. name: broker-etcd-auth-secret
  116. namespace: openshift-ansible-service-broker
  117. contents:
  118. - path: client.crt
  119. data: '{{ etcd_client_cert }}'
  120. - path: client.key
  121. data: '{{ etcd_client_key }}'
  122. - oc_secret:
  123. state: list
  124. namespace: openshift-ansible-service-broker
  125. name: asb-client
  126. register: asb_client_secret
  127. - set_fact:
  128. service_ca_crt: "{{ asb_client_secret.results.results.0.data['service-ca.crt'] }}"
  129. # Using oc_obj because oc_service doesn't seem to allow annotations
  130. # TODO: Extend oc_service to allow annotations
  131. - name: create ansible-service-broker service
  132. oc_obj:
  133. name: asb
  134. namespace: openshift-ansible-service-broker
  135. state: present
  136. kind: Service
  137. content:
  138. path: /tmp/asbsvcout
  139. data:
  140. apiVersion: v1
  141. kind: Service
  142. metadata:
  143. name: asb
  144. namespace: openshift-ansible-service-broker
  145. labels:
  146. app: openshift-ansible-service-broker
  147. service: asb
  148. annotations:
  149. service.alpha.openshift.io/serving-cert-secret-name: asb-tls
  150. spec:
  151. ports:
  152. - name: port-1338
  153. port: 1338
  154. targetPort: 1338
  155. protocol: TCP
  156. selector:
  157. app: openshift-ansible-service-broker
  158. service: asb
  159. - name: create asb-etcd service
  160. oc_obj:
  161. name: asb-etcd
  162. namespace: openshift-ansible-service-broker
  163. state: present
  164. kind: Service
  165. content:
  166. path: /tmp/asbetcdsvcout
  167. data:
  168. apiVersion: v1
  169. kind: Service
  170. metadata:
  171. name: asb-etcd
  172. labels:
  173. app: etcd
  174. service: asb-etcd
  175. annotations:
  176. service.alpha.openshift.io/serving-cert-secret-name: etcd-tls
  177. spec:
  178. ports:
  179. - name: port-2379
  180. port: 2379
  181. targetPort: 2379
  182. protocol: TCP
  183. selector:
  184. app: etcd
  185. service: asb-etcd
  186. - name: create route for ansible-service-broker service
  187. oc_route:
  188. name: asb-1338
  189. namespace: openshift-ansible-service-broker
  190. state: present
  191. labels:
  192. app: openshift-ansible-service-broker
  193. service: asb
  194. service_name: asb
  195. port: 1338
  196. tls_termination: Reencrypt
  197. - name: create persistent volume claim for etcd
  198. oc_obj:
  199. name: etcd
  200. namespace: openshift-ansible-service-broker
  201. state: present
  202. kind: PersistentVolumeClaim
  203. content:
  204. path: /tmp/pvcout
  205. data:
  206. apiVersion: v1
  207. kind: PersistentVolumeClaim
  208. metadata:
  209. name: etcd
  210. namespace: openshift-ansible-service-broker
  211. spec:
  212. accessModes:
  213. - ReadWriteOnce
  214. resources:
  215. requests:
  216. storage: 1Gi
  217. - name: Create Ansible Service Broker deployment config
  218. oc_obj:
  219. name: asb
  220. namespace: openshift-ansible-service-broker
  221. state: present
  222. kind: DeploymentConfig
  223. content:
  224. path: /tmp/dcout
  225. data:
  226. apiVersion: v1
  227. kind: DeploymentConfig
  228. metadata:
  229. name: asb
  230. labels:
  231. app: openshift-ansible-service-broker
  232. service: asb
  233. spec:
  234. replicas: 1
  235. selector:
  236. app: openshift-ansible-service-broker
  237. strategy:
  238. type: Rolling
  239. template:
  240. metadata:
  241. labels:
  242. app: openshift-ansible-service-broker
  243. service: asb
  244. spec:
  245. serviceAccount: asb
  246. containers:
  247. - image: "{{ ansible_service_broker_image }}"
  248. name: asb
  249. imagePullPolicy: IfNotPresent
  250. volumeMounts:
  251. - name: config-volume
  252. mountPath: /etc/ansible-service-broker
  253. - name: asb-tls
  254. mountPath: /etc/tls/private
  255. - name: asb-etcd-auth
  256. mountPath: /var/run/asb-etcd-auth
  257. ports:
  258. - containerPort: 1338
  259. protocol: TCP
  260. env:
  261. - name: BROKER_CONFIG
  262. value: /etc/ansible-service-broker/config.yaml
  263. resources: {}
  264. terminationMessagePath: /tmp/termination-log
  265. readinessProbe:
  266. httpGet:
  267. port: 1338
  268. path: /healthz
  269. scheme: HTTPS
  270. initialDelaySeconds: 15
  271. timeoutSeconds: 1
  272. livenessProbe:
  273. httpGet:
  274. port: 1338
  275. path: /healthz
  276. scheme: HTTPS
  277. initialDelaySeconds: 15
  278. timeoutSeconds: 1
  279. volumes:
  280. - name: config-volume
  281. configMap:
  282. name: broker-config
  283. items:
  284. - key: broker-config
  285. path: config.yaml
  286. - name: asb-tls
  287. secret:
  288. secretName: asb-tls
  289. - name: asb-etcd-auth
  290. secret:
  291. secretName: broker-etcd-auth-secret
  292. - name: Create asb-etcd deployment config
  293. oc_obj:
  294. name: etcd
  295. namespace: openshift-ansible-service-broker
  296. state: present
  297. kind: DeploymentConfig
  298. content:
  299. path: /tmp/dcout
  300. data:
  301. apiVersion: v1
  302. kind: DeploymentConfig
  303. metadata:
  304. name: asb-etcd
  305. labels:
  306. app: etcd
  307. service: asb-etcd
  308. spec:
  309. replicas: 1
  310. selector:
  311. app: etcd
  312. strategy:
  313. type: Rolling
  314. template:
  315. metadata:
  316. labels:
  317. app: etcd
  318. service: asb-etcd
  319. spec:
  320. serviceAccount: asb
  321. containers:
  322. - image: "{{ ansible_service_broker_etcd_image }}"
  323. name: etcd
  324. imagePullPolicy: IfNotPresent
  325. terminationMessagePath: /tmp/termination-log
  326. workingDir: /etcd
  327. args:
  328. - "{{ ansible_service_broker_etcd_image_etcd_path }}"
  329. - "--data-dir=/data"
  330. - "--listen-client-urls=https://0.0.0.0:2379"
  331. - "--advertise-client-urls=https://asb-etcd.openshift-ansible-service-broker.svc:2379"
  332. - "--client-cert-auth"
  333. - "--trusted-ca-file=/var/run/etcd-auth-secret/ca.crt"
  334. - "--cert-file=/etc/tls/private/tls.crt"
  335. - "--key-file=/etc/tls/private/tls.key"
  336. ports:
  337. - containerPort: 2379
  338. protocol: TCP
  339. env:
  340. - name: ETCDCTL_API
  341. value: "3"
  342. volumeMounts:
  343. - name: etcd
  344. mountPath: /data
  345. - name: etcd-tls
  346. mountPath: /etc/tls/private
  347. - name: etcd-auth
  348. mountPath: /var/run/etcd-auth-secret
  349. volumes:
  350. - name: etcd
  351. persistentVolumeClaim:
  352. claimName: etcd
  353. - name: etcd-tls
  354. secret:
  355. secretName: etcd-tls
  356. - name: etcd-auth
  357. secret:
  358. secretName: etcd-auth-secret
  359. # TODO: saw a oc_configmap in the library, but didn't understand how to get it to do the following:
  360. - name: Create config map for ansible-service-broker
  361. oc_obj:
  362. name: broker-config
  363. namespace: openshift-ansible-service-broker
  364. state: present
  365. kind: ConfigMap
  366. content:
  367. path: /tmp/cmout
  368. data:
  369. apiVersion: v1
  370. kind: ConfigMap
  371. metadata:
  372. name: broker-config
  373. namespace: openshift-ansible-service-broker
  374. labels:
  375. app: openshift-ansible-service-broker
  376. data:
  377. broker-config: |
  378. registry:
  379. - type: {{ ansible_service_broker_registry_type }}
  380. name: {{ ansible_service_broker_registry_name }}
  381. url: {{ ansible_service_broker_registry_url }}
  382. org: {{ ansible_service_broker_registry_organization }}
  383. tag: {{ ansible_service_broker_registry_tag }}
  384. white_list: {{ ansible_service_broker_registry_whitelist | to_yaml }}
  385. - type: local_openshift
  386. name: localregistry
  387. namespaces: ['openshift']
  388. white_list: {{ ansible_service_broker_local_registry_whitelist | to_yaml }}
  389. dao:
  390. etcd_host: asb-etcd.openshift-ansible-service-broker.svc
  391. etcd_port: 2379
  392. etcd_ca_file: /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
  393. etcd_client_cert: /var/run/asb-etcd-auth/client.crt
  394. etcd_client_key: /var/run/asb-etcd-auth/client.key
  395. log:
  396. stdout: true
  397. level: {{ ansible_service_broker_log_level }}
  398. color: true
  399. openshift:
  400. host: ""
  401. ca_file: ""
  402. bearer_token_file: ""
  403. sandbox_role: {{ ansible_service_broker_sandbox_role }}
  404. image_pull_policy: {{ ansible_service_broker_image_pull_policy }}
  405. keep_namespace: {{ ansible_service_broker_keep_namespace | bool | lower }}
  406. keep_namespace_on_error: {{ ansible_service_broker_keep_namespace_on_error | bool | lower }}
  407. broker:
  408. dev_broker: {{ ansible_service_broker_dev_broker | bool | lower }}
  409. bootstrap_on_startup: {{ ansible_service_broker_bootstrap_on_startup | bool | lower }}
  410. refresh_interval: {{ ansible_service_broker_refresh_interval }}
  411. launch_apb_on_bind: {{ ansible_service_broker_launch_apb_on_bind | bool | lower }}
  412. output_request: {{ ansible_service_broker_output_request | bool | lower }}
  413. recovery: {{ ansible_service_broker_recovery | bool | lower }}
  414. ssl_cert_key: /etc/tls/private/tls.key
  415. ssl_cert: /etc/tls/private/tls.crt
  416. auto_escalate: {{ ansible_service_broker_auto_escalate }}
  417. auth:
  418. - type: basic
  419. enabled: false
  420. - oc_secret:
  421. name: asb-registry-auth
  422. namespace: openshift-ansible-service-broker
  423. state: present
  424. contents:
  425. - path: username
  426. data: "{{ ansible_service_broker_registry_user }}"
  427. - path: password
  428. data: "{{ ansible_service_broker_registry_password }}"
  429. - name: Create the Broker resource in the catalog
  430. oc_obj:
  431. name: ansible-service-broker
  432. state: present
  433. kind: ClusterServiceBroker
  434. content:
  435. path: /tmp/brokerout
  436. data:
  437. apiVersion: servicecatalog.k8s.io/v1beta1
  438. kind: ClusterServiceBroker
  439. metadata:
  440. name: ansible-service-broker
  441. spec:
  442. url: https://asb.openshift-ansible-service-broker.svc:1338/ansible-service-broker
  443. authInfo:
  444. bearer:
  445. secretRef:
  446. name: asb-client
  447. namespace: openshift-ansible-service-broker
  448. kind: Secret
  449. caBundle: "{{ service_ca_crt }}"