install.yml 12 KB

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