---
- name: create client token secret
  oc_obj:
    name: templateservicebroker-client
    namespace: openshift-template-service-broker
    state: present
    kind: Secret
    content:
      path: /tmp/tsbclientsecretout
      data:
        apiVersion: v1
        kind: Secret
        metadata:
          name: templateservicebroker-client
          namespace: openshift-template-service-broker
          annotations:
            kubernetes.io/service-account.name: templateservicebroker-client
        type: kubernetes.io/service-account-token

- oc_secret:
    state: list
    namespace: openshift-template-service-broker
    name: templateservicebroker-client
  register: tsb_client_secret

- set_fact:
    service_ca_crt: "{{ tsb_client_secret.module_results.results.0.data['service-ca.crt'] }}"

- name: Create the Broker resource in the catalog
  oc_obj:
    name: template-service-broker
    state: present
    kind: ClusterServiceBroker
    content:
      path: /tmp/brokerout
      data:
        apiVersion: servicecatalog.k8s.io/v1beta1
        kind: ClusterServiceBroker
        metadata:
          name: template-service-broker
        spec:
          url: https://apiserver.openshift-template-service-broker.svc:443/brokers/template.openshift.io
          insecureSkipTLSVerify: false
          authInfo:
            bearer:
              secretRef:
                name: templateservicebroker-client
                namespace: openshift-template-service-broker
                kind: Secret
          caBundle: "{{ service_ca_crt }}"
