main.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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: file path="{{ copy_examples_mktemp.stdout }}" mode=0777
  20. run_once: True
  21. - name: Create tar of OpenShift examples
  22. local_action: command tar -C "{{ role_path }}/files/examples/latest/" -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: file path="{{ copy_examples_mktemp.stdout }}/openshift-examples.tar" mode=0744
  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 for oreg_url
  45. command: >
  46. {{ openshift_client_binary }} create secret docker-registry imagestreamsecret
  47. --docker-server={{ registry_host }} --docker-username={{ oreg_auth_user }}
  48. --docker-email=openshift@openshift.com --docker-password={{ oreg_auth_password }}
  49. --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift
  50. when:
  51. - openshift_examples_load_rhel | bool
  52. - oreg_auth_password is defined
  53. register: oex_imagestream_import_secret
  54. failed_when: "'already exists' not in oex_imagestream_import_secret.stderr and oex_imagestream_import_secret.rc != 0"
  55. changed_when: false
  56. - name: Create imagestream import secrets for any additional registries
  57. command: >
  58. {{ openshift_client_binary }} create secret docker-registry o-a-{{ item.host | hash('md5') }}
  59. --docker-server={{ item.host }} --docker-username={{ item.user }}
  60. --docker-email=openshift@openshift.com --docker-password={{ item.password }}
  61. --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift
  62. when:
  63. - openshift_additional_registry_credentials != []
  64. with_items:
  65. - "{{ openshift_additional_registry_credentials }}"
  66. register: oex_additional_creds
  67. failed_when: "'already exists' not in oex_additional_creds.stderr and oex_additional_creds.rc != 0"
  68. - name: Modify registry paths if registry_url is not registry.redhat.io
  69. shell: >
  70. find {{ examples_base }} -type f | xargs -n 1 sed -i 's|registry.redhat.io|{{ registry_host | quote }}|g'
  71. when: registry_host != '' and openshift_examples_modify_imagestreams | default(False) | bool
  72. # RHEL and Centos image streams are mutually exclusive
  73. - name: Import RHEL streams
  74. command: >
  75. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  76. when: openshift_examples_load_rhel | bool
  77. with_items:
  78. - "{{ rhel_image_streams }}"
  79. register: oex_import_rhel_streams
  80. failed_when: "'already exists' not in oex_import_rhel_streams.stderr and oex_import_rhel_streams.rc != 0"
  81. changed_when: false
  82. retries: 3
  83. until: oex_import_rhel_streams is succeeded
  84. - name: Import Centos Image streams
  85. command: >
  86. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  87. when: openshift_examples_load_centos | bool
  88. with_items:
  89. - "{{ centos_image_streams }}"
  90. register: oex_import_centos_streams
  91. failed_when: "'already exists' not in oex_import_centos_streams.stderr and oex_import_centos_streams.rc != 0"
  92. changed_when: false
  93. retries: 3
  94. until: oex_import_centos_streams is succeeded
  95. - name: Import db templates
  96. command: >
  97. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ db_templates_base }}
  98. when: openshift_examples_load_db_templates | bool
  99. register: oex_import_db_templates
  100. failed_when: "'already exists' not in oex_import_db_templates.stderr and oex_import_db_templates.rc != 0"
  101. changed_when: false
  102. retries: 3
  103. until: oex_import_db_templates is succeeded
  104. - name: Remove defunct quickstart template files
  105. file:
  106. path: "{{ item }}"
  107. state: absent
  108. with_items:
  109. - "{{ quickstarts_base }}/nodejs.json"
  110. - "{{ quickstarts_base }}/cakephp.json"
  111. - "{{ quickstarts_base }}/dancer.json"
  112. - "{{ quickstarts_base }}/django.json"
  113. - name: Remove defunct quickstart templates from openshift namespace
  114. command: "{{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  115. with_items:
  116. - nodejs-example
  117. - cakephp-example
  118. - dancer-example
  119. - django-example
  120. register: oex_delete_defunct_quickstart_templates
  121. failed_when: "'not found' not in oex_delete_defunct_quickstart_templates.stderr and oex_delete_defunct_quickstart_templates.rc != 0"
  122. changed_when: false
  123. - name: Import quickstart-templates
  124. command: >
  125. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ quickstarts_base }}
  126. when: openshift_examples_load_quickstarts | bool
  127. register: oex_import_quickstarts
  128. failed_when: "'already exists' not in oex_import_quickstarts.stderr and oex_import_quickstarts.rc != 0"
  129. changed_when: false
  130. retries: 3
  131. until: oex_import_quickstarts is succeeded
  132. - name: Remove old xPaas template files
  133. file:
  134. path: "{{ item }}"
  135. state: absent
  136. with_items:
  137. - "{{ xpaas_templates_base }}/sso70-basic.json"
  138. - name: Remove old xPaas templates from openshift namespace
  139. command: "{{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  140. with_items:
  141. - sso70-basic
  142. register: oex_delete_old_xpaas_templates
  143. failed_when: "'not found' not in oex_delete_old_xpaas_templates.stderr and oex_delete_old_xpaas_templates.rc != 0"
  144. changed_when: false
  145. - name: Import xPaas image streams
  146. command: >
  147. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_image_streams }}
  148. when: openshift_examples_load_xpaas | bool
  149. register: oex_import_xpaas_streams
  150. failed_when: "'already exists' not in oex_import_xpaas_streams.stderr and oex_import_xpaas_streams.rc != 0"
  151. changed_when: false
  152. retries: 3
  153. until: oex_import_xpaas_streams is succeeded
  154. - name: Import xPaas templates
  155. command: >
  156. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_templates_base }}
  157. when: openshift_examples_load_xpaas | bool
  158. register: oex_import_xpaas_templates
  159. failed_when: "'already exists' not in oex_import_xpaas_templates.stderr and oex_import_xpaas_templates.rc != 0"
  160. changed_when: false
  161. retries: 3
  162. until: oex_import_xpaas_templates is succeeded