install_awx.yml 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # Copyright 2022 Dell Inc. or its subsidiaries. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. ---
  15. # Tasks for installing AWX
  16. - name: Get all namespaces
  17. command: kubectl get ns
  18. changed_when: false
  19. register: namespaces
  20. - name: Create namespace
  21. command: "kubectl create namespace {{ awx_namespace }}"
  22. changed_when: true
  23. when: "'awx' not in namespaces.stdout"
  24. - name: Setting the current namespace for kubectl
  25. command: "kubectl config set-context --current --namespace={{ awx_namespace }}"
  26. changed_when: false
  27. - name: Installing jq package
  28. package:
  29. name: jq
  30. state: present
  31. - name: Creating and deploying AWX operator
  32. block:
  33. - name: Creating directory for deploying awx-operator
  34. file:
  35. path: "{{ awx_operator_folder }}"
  36. state: directory
  37. mode: "{{ file_perm }}"
  38. - name: Check for awx-operator status
  39. stat:
  40. path: "{{ awx_manager_file }}"
  41. register: awx_operator_repo
  42. - name: Cloning awx-operator from github
  43. git:
  44. repo: "{{ awx_operator_link }}"
  45. dest: "{{ awx_operator_folder }}"
  46. version: "{{ awx_operator_version }}"
  47. when: not awx_operator_repo.stat.exists
  48. - name: Modifying livenessprobe value
  49. replace:
  50. path: "{{ awx_manager_file }}"
  51. regexp: "{{ liveness_probe_initial }}"
  52. replace: "{{ liveness_probe_final }}"
  53. - name: Modifying readinessprobe value
  54. replace:
  55. path: "{{ awx_manager_file }}"
  56. regexp: "{{ readiness_probe_initial }}"
  57. replace: "{{ readiness_probe_final }}"
  58. - name: Deploying awx-operator
  59. command: make deploy
  60. changed_when: false
  61. args:
  62. chdir: "{{ awx_operator_folder }}"
  63. environment:
  64. NAMESPACE: "{{ awx_namespace }}"
  65. rescue:
  66. - name: Cleaning awx-operator folder
  67. file:
  68. path: "{{ awx_operator_folder }}"
  69. state: absent
  70. - name: Creating directory for deploying awx-operator
  71. file:
  72. path: "{{ awx_operator_folder }}"
  73. state: directory
  74. mode: "{{ file_perm }}"
  75. - name: Cloning awx-operator from github
  76. git:
  77. repo: "{{ awx_operator_link }}"
  78. dest: "{{ awx_operator_folder }}"
  79. version: "{{ awx_operator_version }}"
  80. - name: Modifying livenessprobe value
  81. replace:
  82. path: "{{ awx_manager_file }}"
  83. regexp: "{{ liveness_probe_initial }}"
  84. replace: "{{ liveness_probe_final }}"
  85. - name: Modifying readinessprobe value
  86. replace:
  87. path: "{{ awx_manager_file }}"
  88. regexp: "{{ readiness_probe_initial }}"
  89. replace: "{{ readiness_probe_final }}"
  90. - name: Deploying awx-operator
  91. command: make deploy
  92. changed_when: false
  93. args:
  94. chdir: "{{ awx_operator_folder }}"
  95. environment:
  96. NAMESPACE: "{{ awx_namespace }}"
  97. - name: Waiting for awx operator deployment
  98. block:
  99. - name: Waiting for awx-operator deployment to be up and running (This might take 10-15 minutes)
  100. command: kubectl wait --for=condition=available deployment awx-operator-controller-manager -n {{ awx_namespace }} --timeout={{ awx_operator_time }}
  101. changed_when: false
  102. rescue:
  103. - name: Display failure message
  104. debug:
  105. msg: "{{ operator_deployment_failure }}"
  106. - name: Get K8s pods
  107. command: "kubectl get pods -n {{ awx_namespace }}"
  108. changed_when: false
  109. register: k8s_pods
  110. - name: Get K8s persistent volumes
  111. command: "kubectl get pv -n {{ awx_namespace }}"
  112. changed_when: false
  113. register: k8s_pvs
  114. - name: Configure host volume as playbooks directory path
  115. replace:
  116. path: "{{ awx_pv_yml_file_path }}"
  117. regexp: 'path: "/etc"'
  118. replace: 'path: "{{ playbook_dir | dirname | dirname }}"'
  119. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  120. - name: Create persistent volume and volumeclaim for projects
  121. command: "kubectl apply -f {{ awx_pv_yml_file_path }}"
  122. changed_when: true
  123. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  124. - name: Create persistent volume for postgres
  125. command: "kubectl apply -f {{ awx_postgres_pv_file_path }}"
  126. changed_when: true
  127. when: "'awx-postgres-pv' not in k8s_pvs.stdout"
  128. - name: Get the docker images
  129. command: buildah images
  130. changed_when: false
  131. register: docker_images
  132. - name: Build the custom-awx-ee image from the docker file (It may take 5-10min)
  133. command: "buildah bud -t custom-awx-ee {{ awx_ee_docker_file }}"
  134. changed_when: false
  135. when: "'custom-awx-ee' not in docker_images.stdout"
  136. retries: "{{ min_retries }}"
  137. - name: Deploy awx
  138. command: "kubectl apply -f {{ awx_yml_file_path }}"
  139. changed_when: true
  140. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  141. - name: Wait for awx pods to get created (This will take 10min)
  142. wait_for:
  143. timeout: "{{ awx_wait_time }}"
  144. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  145. - name: Install awxkit using pip3
  146. pip:
  147. name: awxkit
  148. state: present
  149. - name: Install awx collection
  150. command: "ansible-galaxy collection install awx.awx:{{ awx_version }}"
  151. changed_when: true
  152. register: installation_status
  153. - name: Fails if the pods go into ImagePullBackOff state
  154. block:
  155. - name: Waiting for awx deployment to be up and running
  156. command: kubectl wait --for=condition=available deployment awx -n {{ awx_namespace }} --timeout={{ awx_deployment_time }}
  157. changed_when: false
  158. rescue:
  159. - name: Display failure message
  160. debug:
  161. msg: "{{ deployment_failure_msg }}"