main.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ---
  2. ######################################################################
  3. # Users, projects, and privileges
  4. - name: Ensure the CFME user exists
  5. oc_user:
  6. state: present
  7. username: "{{ openshift_cfme_user }}"
  8. - name: Ensure the CFME namespace exists with CFME user as admin
  9. oc_project:
  10. state: present
  11. name: "{{ openshift_cfme_project }}"
  12. display_name: "{{ openshift_cfme_project_description }}"
  13. admin: "{{ openshift_cfme_user }}"
  14. - name: Ensure the CFME namespace service account is privileged
  15. oc_adm_policy_user:
  16. namespace: "{{ openshift_cfme_project }}"
  17. user: "{{ openshift_cfme_service_account }}"
  18. resource_kind: scc
  19. resource_name: privileged
  20. state: present
  21. ######################################################################
  22. # NFS
  23. - name: Ensure the /exports/ directory exists
  24. file:
  25. path: /exports/
  26. state: directory
  27. mode: 0755
  28. owner: root
  29. group: root
  30. - name: Ensure the miq-pv0X export directories exist
  31. file:
  32. path: "/exports/{{ item }}"
  33. state: directory
  34. mode: 0775
  35. owner: root
  36. group: root
  37. with_items: "{{ openshift_cfme_pv_exports }}"
  38. - name: Ensure the NFS exports for CFME PVs exist
  39. copy:
  40. src: openshift_cfme.exports
  41. dest: /etc/exports.d/openshift_cfme.exports
  42. register: nfs_exports_updated
  43. - name: Ensure the NFS export table is refreshed if exports were added
  44. command: exportfs -ar
  45. when:
  46. - nfs_exports_updated.changed
  47. ######################################################################
  48. # Create the required CFME PVs. Check out these online docs if you
  49. # need a refresher on includes looping with items:
  50. # * http://docs.ansible.com/ansible/playbooks_loops.html#loops-and-includes-in-2-0
  51. # * http://stackoverflow.com/a/35128533
  52. #
  53. # TODO: Handle the case where a PV template is updated in
  54. # openshift-ansible and the change needs to be landed on the managed
  55. # cluster.
  56. - include: create_pvs.yml
  57. with_items: "{{ openshift_cfme_pv_data }}"
  58. ######################################################################
  59. # CFME App Template
  60. #
  61. # Note, this is different from the create_pvs.yml tasks in that the
  62. # application template does not require any jinja2 evaluation.
  63. #
  64. # TODO: Handle the case where the server template is updated in
  65. # openshift-ansible and the change needs to be landed on the managed
  66. # cluster.
  67. - name: Check if the CFME Server template has been created already
  68. oc_obj:
  69. namespace: "{{ openshift_cfme_project }}"
  70. state: list
  71. kind: template
  72. name: manageiq
  73. register: miq_server_check
  74. - name: Copy over CFME Server template
  75. copy:
  76. src: miq-template.yaml
  77. dest: "{{ template_dir }}/miq-template.yaml"
  78. - name: Ensure the server template was read from disk
  79. debug:
  80. var=r_openshift_cfme_miq_template_content
  81. - name: Ensure CFME Server Template exists
  82. oc_obj:
  83. namespace: "{{ openshift_cfme_project }}"
  84. kind: template
  85. name: "manageiq"
  86. state: present
  87. content: "{{ r_openshift_cfme_miq_template_content }}"
  88. ######################################################################
  89. # Let's do this
  90. - name: Ensure the CFME Server is created
  91. oc_process:
  92. namespace: "{{ openshift_cfme_project }}"
  93. template_name: manageiq
  94. create: True
  95. params:
  96. APPLICATION_IMG_NAME: "{{ openshift_cfme_application_img_name }}"
  97. POSTGRESQL_IMG_NAME: "{{ openshift_cfme_postgresql_img_name }}"
  98. MEMCACHED_IMG_NAME: "{{ openshift_cfme_memcached_img_name }}"
  99. APPLICATION_IMG_TAG: "{{ openshift_cfme_application_img_tag }}"
  100. POSTGRESQL_IMG_TAG: "{{ openshift_cfme_postgresql_img_tag }}"
  101. MEMCACHED_IMG_TAG: "{{ openshift_cfme_memcached_img_tag }}"
  102. register: cfme_new_app_process
  103. run_once: True
  104. when:
  105. # User said to install CFME in their inventory
  106. - openshift_cfme_install_app | bool
  107. # # The server app doesn't exist already
  108. # - not miq_server_check.results.results.0
  109. - debug:
  110. var: cfme_new_app_process
  111. ######################################################################
  112. # Various cleanup steps
  113. # TODO: Not sure what to do about this right now. Might be able to
  114. # just delete it? This currently warns about "Unable to find
  115. # '<TEMP_DIR>' in expected paths."
  116. - name: Ensure the temporary PV/App templates are erased
  117. file:
  118. path: "{{ item }}"
  119. state: absent
  120. with_fileglob:
  121. - "{{ template_dir }}/*.yaml"
  122. - name: Ensure the temporary PV/app template directory is erased
  123. file:
  124. path: "{{ template_dir }}"
  125. state: absent
  126. ######################################################################
  127. - name: Status update
  128. debug:
  129. msg: >
  130. CFME has been deployed. Note that there will be a delay before
  131. it is fully initialized.