main.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ---
  2. ######################################################################
  3. # Copying Examples
  4. #
  5. # We used to use the copy module to transfer the openshift examples to
  6. # the remote. Then it started taking more than a minute to transfer
  7. # the files. As noted in the module:
  8. #
  9. # "The 'copy' module recursively copy facility does not scale to
  10. # lots (>hundreds) of files."
  11. #
  12. # The `synchronize` module is suggested as an alternative, we can't
  13. # use it either due to changes introduced in Ansible 2.x.
  14. - name: Create local temp dir for OpenShift examples copy
  15. local_action: command mktemp -d /tmp/openshift-ansible-XXXXXXX
  16. register: copy_examples_mktemp
  17. run_once: True
  18. - name: Chmod local temp dir for OpenShift examples copy
  19. local_action: command chmod 777 "{{ copy_examples_mktemp.stdout }}"
  20. run_once: True
  21. - name: Create tar of OpenShift examples
  22. local_action: command tar -C "{{ role_path }}/files/examples/{{ content_version }}/" -cvf "{{ copy_examples_mktemp.stdout }}/openshift-examples.tar" .
  23. args:
  24. # Disables the following warning:
  25. # Consider using unarchive module rather than running tar
  26. warn: no
  27. - name: Chmod local temp dir for OpenShift examples copy
  28. local_action: command chmod 744 "{{ copy_examples_mktemp.stdout }}/openshift-examples.tar"
  29. run_once: True
  30. - name: Create the remote OpenShift examples directory
  31. file:
  32. dest: "{{ examples_base }}"
  33. state: directory
  34. mode: 0755
  35. - name: Unarchive the OpenShift examples on the remote
  36. unarchive:
  37. src: "{{ copy_examples_mktemp.stdout }}/openshift-examples.tar"
  38. dest: "{{ examples_base }}/"
  39. - name: Cleanup the OpenShift Examples temp dir
  40. local_action: file dest="{{ copy_examples_mktemp.stdout }}" state=absent
  41. # Done copying examples
  42. ######################################################################
  43. # Begin image streams
  44. - name: Create imagestream import secret
  45. command: >
  46. {{ openshift_client_binary }} create secret docker-registry imagestreamsecret --docker-server={{ registry_host }} --docker-username={{ oreg_auth_user }} --docker-email=openshift@openshift.com --docker-password={{ oreg_auth_password }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift
  47. when:
  48. - openshift_examples_load_rhel | bool
  49. - oreg_auth_password is defined
  50. with_items:
  51. - "{{ rhel_image_streams }}"
  52. register: oex_imagestream_import_secret
  53. failed_when: "'already exists' not in oex_imagestream_import_secret.stderr and oex_imagestream_import_secret.rc != 0"
  54. changed_when: false
  55. - name: Modify registry paths if registry_url is not registry.redhat.io
  56. shell: >
  57. find {{ examples_base }} -type f | xargs -n 1 sed -i 's|registry.redhat.io|{{ registry_host | quote }}|g'
  58. when: registry_host != '' and openshift_examples_modify_imagestreams | default(False) | bool
  59. # RHEL and Centos image streams are mutually exclusive
  60. - name: Import RHEL streams
  61. command: >
  62. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  63. when: openshift_examples_load_rhel | bool
  64. with_items:
  65. - "{{ rhel_image_streams }}"
  66. register: oex_import_rhel_streams
  67. failed_when: "'already exists' not in oex_import_rhel_streams.stderr and oex_import_rhel_streams.rc != 0"
  68. changed_when: false
  69. - name: Import Centos Image streams
  70. command: >
  71. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  72. when: openshift_examples_load_centos | bool
  73. with_items:
  74. - "{{ centos_image_streams }}"
  75. register: oex_import_centos_streams
  76. failed_when: "'already exists' not in oex_import_centos_streams.stderr and oex_import_centos_streams.rc != 0"
  77. changed_when: false
  78. - name: Import db templates
  79. command: >
  80. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ db_templates_base }}
  81. when: openshift_examples_load_db_templates | bool
  82. register: oex_import_db_templates
  83. failed_when: "'already exists' not in oex_import_db_templates.stderr and oex_import_db_templates.rc != 0"
  84. changed_when: false
  85. - name: Remove defunct quickstart template files
  86. file:
  87. path: "{{ item }}"
  88. state: absent
  89. with_items:
  90. - "{{ quickstarts_base }}/nodejs.json"
  91. - "{{ quickstarts_base }}/cakephp.json"
  92. - "{{ quickstarts_base }}/dancer.json"
  93. - "{{ quickstarts_base }}/django.json"
  94. - name: Remove defunct quickstart templates from openshift namespace
  95. command: "{{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  96. with_items:
  97. - nodejs-example
  98. - cakephp-example
  99. - dancer-example
  100. - django-example
  101. register: oex_delete_defunct_quickstart_templates
  102. failed_when: "'not found' not in oex_delete_defunct_quickstart_templates.stderr and oex_delete_defunct_quickstart_templates.rc != 0"
  103. changed_when: false
  104. - name: Import quickstart-templates
  105. command: >
  106. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ quickstarts_base }}
  107. when: openshift_examples_load_quickstarts | bool
  108. register: oex_import_quickstarts
  109. failed_when: "'already exists' not in oex_import_quickstarts.stderr and oex_import_quickstarts.rc != 0"
  110. changed_when: false
  111. - name: Remove old xPaas template files
  112. file:
  113. path: "{{ item }}"
  114. state: absent
  115. with_items:
  116. - "{{ xpaas_templates_base }}/sso70-basic.json"
  117. - name: Remove old xPaas templates from openshift namespace
  118. command: "{{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  119. with_items:
  120. - sso70-basic
  121. register: oex_delete_old_xpaas_templates
  122. failed_when: "'not found' not in oex_delete_old_xpaas_templates.stderr and oex_delete_old_xpaas_templates.rc != 0"
  123. changed_when: false
  124. - name: Import xPaas image streams
  125. command: >
  126. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_image_streams }}
  127. when: openshift_examples_load_xpaas | bool
  128. register: oex_import_xpaas_streams
  129. failed_when: "'already exists' not in oex_import_xpaas_streams.stderr and oex_import_xpaas_streams.rc != 0"
  130. changed_when: false
  131. - name: Import xPaas templates
  132. command: >
  133. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_templates_base }}
  134. when: openshift_examples_load_xpaas | bool
  135. register: oex_import_xpaas_templates
  136. failed_when: "'already exists' not in oex_import_xpaas_templates.stderr and oex_import_xpaas_templates.rc != 0"
  137. changed_when: false