install_awx.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. # Copyright 2021 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: Deploying awx-operator
  53. command: make deploy
  54. changed_when: false
  55. args:
  56. chdir: "{{ awx_operator_folder }}"
  57. - name: Get K8s pods
  58. command: "kubectl get pods -n {{ awx_namespace }}"
  59. changed_when: false
  60. register: k8s_pods
  61. - name: Get K8s persistent volumes
  62. command: "kubectl get pv -n {{ awx_namespace }}"
  63. changed_when: false
  64. register: k8s_pvs
  65. - name: Configure host volume as playbooks directory path
  66. replace:
  67. path: "{{ awx_pv_yml_file_path }}"
  68. regexp: 'path: "/etc"'
  69. replace: 'path: "{{ playbook_dir | dirname | dirname }}"'
  70. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  71. - name: Create persistent volume and volumeclaim for projects
  72. command: "kubectl apply -f {{ awx_pv_yml_file_path }}"
  73. changed_when: true
  74. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  75. - name: Create persistent volume for postgres
  76. command: "kubectl apply -f {{ awx_postgres_pv_file_path }}"
  77. changed_when: true
  78. when: "'awx-postgres-pv' not in k8s_pvs.stdout"
  79. - name: Get the docker images
  80. command: buildah images
  81. changed_when: false
  82. register: docker_images
  83. - name: Build the custom-awx-ee image from the docker file (It may take 5-10min)
  84. command: "buildah bud -t custom-awx-ee {{ awx_ee_docker_file }}"
  85. changed_when: false
  86. when: "'custom-awx-ee' not in docker_images.stdout"
  87. retries: "{{ min_retries }}"
  88. - name: Waiting for awx-operator deployment to be up and running
  89. command: kubectl wait --for=condition=available deployment awx-operator-controller-manager -n {{ awx_namespace }} --timeout={{ awx_operator_time }}
  90. changed_when: false
  91. - name: Deploy awx
  92. command: "kubectl apply -f {{ awx_yml_file_path }}"
  93. changed_when: true
  94. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  95. - name: Install awxkit using pip3
  96. pip:
  97. name: awxkit
  98. state: present
  99. - name: Install awx collection
  100. command: "ansible-galaxy collection install awx.awx:{{ awx_version }}"
  101. changed_when: true
  102. register: installation_status
  103. - name: Wait for awx pods to get created
  104. wait_for:
  105. timeout: "{{ awx_wait_time }}"
  106. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  107. - name: Fails if the pods go into ImagePullBackOff state
  108. block:
  109. - name: Waiting for awx deployment to be up and running
  110. command: kubectl wait --for=condition=available deployment awx -n {{ awx_namespace }} --timeout={{ awx_deployment_time }}
  111. changed_when: false
  112. rescue:
  113. - name: Display failure message
  114. debug:
  115. msg: "{{ deployment_failure_msg }}"