main.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ---
  2. - name: Create temp directory for kubeconfig
  3. command: mktemp -d /tmp/openshift-ansible-XXXXXX
  4. register: mktemp
  5. changed_when: False
  6. - set_fact:
  7. openshift_hosted_kubeconfig: "{{ mktemp.stdout }}/admin.kubeconfig"
  8. - name: Copy the admin client config(s)
  9. command: >
  10. cp {{ openshift_master_config_dir }}/admin.kubeconfig {{ openshift_hosted_kubeconfig }}
  11. changed_when: False
  12. - name: Determine if docker-registry service exists
  13. command: >
  14. {{ openshift.common.client_binary }} get svc/docker-registry
  15. --config={{ openshift_hosted_kubeconfig }}
  16. -n default
  17. register: check_docker_registry_exists
  18. failed_when: false
  19. changed_when: false
  20. - name: Create passthrough route for docker-registry
  21. command: >
  22. {{ openshift.common.client_binary }} create route passthrough
  23. --service docker-registry
  24. --config={{ openshift_hosted_kubeconfig }}
  25. -n default
  26. register: create_docker_registry_route
  27. changed_when: "'already exists' not in create_docker_registry_route.stderr"
  28. failed_when: "'already exists' not in create_docker_registry_route.stderr and create_docker_registry_route.rc != 0"
  29. when: check_docker_registry_exists.rc == 0
  30. - name: Create passthrough route for registry-console
  31. command: >
  32. {{ openshift.common.client_binary }} create route passthrough
  33. --service registry-console
  34. --port registry-console
  35. --config={{ openshift_hosted_kubeconfig }}
  36. -n default
  37. register: create_registry_console_route
  38. changed_when: "'already exists' not in create_registry_console_route.stderr"
  39. failed_when: "'already exists' not in create_registry_console_route.stderr and create_registry_console_route.rc != 0"
  40. when: check_docker_registry_exists.rc == 0
  41. - name: Retrieve docker-registry route
  42. command: >
  43. {{ openshift.common.client_binary }} get route docker-registry
  44. -o jsonpath='{.spec.host}'
  45. --config={{ openshift_hosted_kubeconfig }}
  46. -n default
  47. register: docker_registry_route
  48. changed_when: false
  49. when: check_docker_registry_exists.rc == 0
  50. - name: Retrieve cockpit kube url
  51. command: >
  52. {{ openshift.common.client_binary }} get route registry-console
  53. -o jsonpath='https://{.spec.host}'
  54. -n default
  55. register: registry_console_cockpit_kube_url
  56. changed_when: false
  57. when: check_docker_registry_exists.rc == 0
  58. - name: Deploy registry-console
  59. command: >
  60. {{ openshift.common.client_binary }} new-app --template=registry-console
  61. {% if openshift_cockpit_deployer_prefix is defined %}-p IMAGE_PREFIX="{{ openshift_cockpit_deployer_prefix }}"{% endif %}
  62. -p OPENSHIFT_OAUTH_PROVIDER_URL="{{ openshift.master.public_api_url }}"
  63. -p REGISTRY_HOST="{{ docker_registry_route.stdout }}"
  64. -p COCKPIT_KUBE_URL="{{ registry_console_cockpit_kube_url.stdout }}"
  65. --config={{ openshift_hosted_kubeconfig }}
  66. -n default
  67. register: deploy_registry_console
  68. changed_when: "'already exists' not in deploy_registry_console.stderr"
  69. failed_when: "'already exists' not in deploy_registry_console.stderr and deploy_registry_console.rc != 0"
  70. when: check_docker_registry_exists.rc == 0
  71. - name: Delete temp directory
  72. file:
  73. name: "{{ mktemp.stdout }}"
  74. state: absent
  75. changed_when: False