main.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. register: cfme_new_app_process
  96. run_once: True
  97. when:
  98. # User said to install CFME in their inventory
  99. - openshift_cfme_install_app | bool
  100. # # The server app doesn't exist already
  101. # - not miq_server_check.results.results.0
  102. - debug:
  103. var: cfme_new_app_process
  104. ######################################################################
  105. # Various cleanup steps
  106. # TODO: Not sure what to do about this right now. Might be able to
  107. # just delete it? This currently warns about "Unable to find
  108. # '<TEMP_DIR>' in expected paths."
  109. - name: Ensure the temporary PV/App templates are erased
  110. file:
  111. path: "{{ item }}"
  112. state: absent
  113. with_fileglob:
  114. - "{{ template_dir }}/*.yaml"
  115. - name: Ensure the temporary PV/app template directory is erased
  116. file:
  117. path: "{{ template_dir }}"
  118. state: absent
  119. ######################################################################
  120. - name: Status update
  121. debug:
  122. msg: >
  123. CFME has been deployed. Note that there will be a delay before
  124. it is fully initialized.