install_awx.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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: Creating directory for deploying awx-operator
  21. file:
  22. path: "{{ awx_operator_folder }}"
  23. state: directory
  24. mode: "{{ file_perm }}"
  25. - name: Check for awx-operator status
  26. stat:
  27. path: "{{ awx_manager_file }}"
  28. register: awx_operator_repo
  29. - name: Cloning awx-operator from github
  30. git:
  31. repo: "{{ awx_operator_link }}"
  32. dest: "{{ awx_operator_folder }}"
  33. version: "{{ awx_tag }}"
  34. when: not awx_operator_repo.stat.exists
  35. - name: Modifying livenessprobe value
  36. replace:
  37. path: "{{ awx_manager_file }}"
  38. regexp: "{{ liveness_probe_initial }}"
  39. replace: "{{ liveness_probe_final }}"
  40. - name: Modifying readinessprobe value
  41. replace:
  42. path: "{{ awx_manager_file }}"
  43. regexp: "{{ readiness_probe_initial }}"
  44. replace: "{{ readiness_probe_final }}"
  45. - name: Create namespace
  46. command: "kubectl create namespace {{ awx_namespace }}"
  47. changed_when: true
  48. when: "'awx' not in namespaces.stdout"
  49. - name: Setting the current namespace for kubectl
  50. command: "kubectl config set-context --current --namespace={{ awx_namespace }}"
  51. changed_when: false
  52. - name: Installing jq package
  53. package:
  54. name: jq
  55. state: present
  56. - name: Deploying awx-operator
  57. command: make deploy
  58. changed_when: false
  59. args:
  60. chdir: "{{ awx_operator_folder }}"
  61. environment:
  62. NAMESPACE: "{{ awx_namespace }}"
  63. - name: Waiting for awx operator deployment {This might take 10-15 minutes}
  64. block:
  65. - name: Waiting for awx-operator deployment to be up and running
  66. command: kubectl wait --for=condition=available deployment awx-operator-controller-manager -n {{ awx_namespace }} --timeout={{ awx_operator_time }}
  67. changed_when: false
  68. rescue:
  69. - name: Display failure message
  70. debug:
  71. msg: "{{ operator_deployment_failure }}"
  72. - name: Get K8s pods
  73. command: "kubectl get pods -n {{ awx_namespace }}"
  74. changed_when: false
  75. register: k8s_pods
  76. - name: Get K8s persistent volumes
  77. command: "kubectl get pv -n {{ awx_namespace }}"
  78. changed_when: false
  79. register: k8s_pvs
  80. - name: Configure host volume as playbooks directory path
  81. replace:
  82. path: "{{ awx_pv_yml_file_path }}"
  83. regexp: 'path: "/etc"'
  84. replace: 'path: "{{ playbook_dir | dirname | dirname }}"'
  85. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  86. - name: Create persistent volume and volumeclaim for projects
  87. command: "kubectl apply -f {{ awx_pv_yml_file_path }}"
  88. changed_when: true
  89. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  90. - name: Create persistent volume for postgres
  91. command: "kubectl apply -f {{ awx_postgres_pv_file_path }}"
  92. changed_when: true
  93. when: "'awx-postgres-pv' not in k8s_pvs.stdout"
  94. - name: Get the docker images
  95. command: buildah images
  96. changed_when: false
  97. register: docker_images
  98. - name: Build the custom-awx-ee image from the docker file (It may take 5-10min)
  99. command: "buildah bud -t custom-awx-ee {{ awx_ee_docker_file }}"
  100. changed_when: false
  101. when: "'custom-awx-ee' not in docker_images.stdout"
  102. retries: "{{ min_retries }}"
  103. - name: Deploy awx
  104. command: "kubectl apply -f {{ awx_yml_file_path }}"
  105. changed_when: true
  106. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  107. - name: Wait for awx pods to get created
  108. wait_for:
  109. timeout: "{{ awx_wait_time }}"
  110. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  111. - name: Install awxkit using pip3
  112. pip:
  113. name: awxkit
  114. state: present
  115. - name: Install awx collection
  116. command: "ansible-galaxy collection install awx.awx:{{ awx_version }}"
  117. changed_when: true
  118. register: installation_status
  119. - name: Fails if the pods go into ImagePullBackOff state
  120. block:
  121. - name: Waiting for awx deployment to be up and running
  122. command: kubectl wait --for=condition=available deployment awx -n {{ awx_namespace }} --timeout={{ awx_deployment_time }}
  123. changed_when: false
  124. rescue:
  125. - name: Display failure message
  126. debug:
  127. msg: "{{ deployment_failure_msg }}"