main.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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/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: 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 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 imagestreamsecret
  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 is defined
  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. - name: Import Centos Image streams
  83. command: >
  84. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ item }}
  85. when: openshift_examples_load_centos | bool
  86. with_items:
  87. - "{{ centos_image_streams }}"
  88. register: oex_import_centos_streams
  89. failed_when: "'already exists' not in oex_import_centos_streams.stderr and oex_import_centos_streams.rc != 0"
  90. changed_when: false
  91. - name: Import db templates
  92. command: >
  93. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ db_templates_base }}
  94. when: openshift_examples_load_db_templates | bool
  95. register: oex_import_db_templates
  96. failed_when: "'already exists' not in oex_import_db_templates.stderr and oex_import_db_templates.rc != 0"
  97. changed_when: false
  98. - name: Remove defunct quickstart template files
  99. file:
  100. path: "{{ item }}"
  101. state: absent
  102. with_items:
  103. - "{{ quickstarts_base }}/nodejs.json"
  104. - "{{ quickstarts_base }}/cakephp.json"
  105. - "{{ quickstarts_base }}/dancer.json"
  106. - "{{ quickstarts_base }}/django.json"
  107. - name: Remove defunct quickstart templates from openshift namespace
  108. command: "{{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  109. with_items:
  110. - nodejs-example
  111. - cakephp-example
  112. - dancer-example
  113. - django-example
  114. register: oex_delete_defunct_quickstart_templates
  115. failed_when: "'not found' not in oex_delete_defunct_quickstart_templates.stderr and oex_delete_defunct_quickstart_templates.rc != 0"
  116. changed_when: false
  117. - name: Import quickstart-templates
  118. command: >
  119. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ quickstarts_base }}
  120. when: openshift_examples_load_quickstarts | bool
  121. register: oex_import_quickstarts
  122. failed_when: "'already exists' not in oex_import_quickstarts.stderr and oex_import_quickstarts.rc != 0"
  123. changed_when: false
  124. - name: Remove old xPaas template files
  125. file:
  126. path: "{{ item }}"
  127. state: absent
  128. with_items:
  129. - "{{ xpaas_templates_base }}/sso70-basic.json"
  130. - name: Remove old xPaas templates from openshift namespace
  131. command: "{{ openshift_client_binary }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift delete templates/{{ item }}"
  132. with_items:
  133. - sso70-basic
  134. register: oex_delete_old_xpaas_templates
  135. failed_when: "'not found' not in oex_delete_old_xpaas_templates.stderr and oex_delete_old_xpaas_templates.rc != 0"
  136. changed_when: false
  137. - name: Import xPaas image streams
  138. command: >
  139. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_image_streams }}
  140. when: openshift_examples_load_xpaas | bool
  141. register: oex_import_xpaas_streams
  142. failed_when: "'already exists' not in oex_import_xpaas_streams.stderr and oex_import_xpaas_streams.rc != 0"
  143. changed_when: false
  144. - name: Import xPaas templates
  145. command: >
  146. {{ openshift_client_binary }} {{ openshift_examples_import_command }} --config={{ openshift.common.config_base }}/master/admin.kubeconfig -n openshift -f {{ xpaas_templates_base }}
  147. when: openshift_examples_load_xpaas | bool
  148. register: oex_import_xpaas_templates
  149. failed_when: "'already exists' not in oex_import_xpaas_templates.stderr and oex_import_xpaas_templates.rc != 0"
  150. changed_when: false