install_awx.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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: Create namespace
  21. command: "kubectl create namespace {{ awx_namespace }}"
  22. changed_when: true
  23. when: "'awx' not in namespaces.stdout"
  24. - name: Get K8s pods
  25. command: "kubectl get pods -n {{ awx_namespace }}"
  26. changed_when: false
  27. register: k8s_pods
  28. - name: Deploy awx-operator
  29. command: "kubectl apply -f {{ awx_operator_yml_file_path }}"
  30. changed_when: true
  31. when: '"awx-operator" not in k8s_pods.stdout'
  32. - name: Get K8s persistent volumes
  33. command: "kubectl get pv -n {{ awx_namespace }}"
  34. changed_when: false
  35. register: k8s_pvs
  36. - name: Configure host volume as playbooks directory path
  37. replace:
  38. path: "{{ awx_pv_yml_file_path }}"
  39. regexp: 'path: "/etc"'
  40. replace: 'path: "{{ playbook_dir | dirname | dirname }}"'
  41. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  42. - name: Create persistent volume and volumeclaim for projects
  43. command: "kubectl apply -f {{ awx_pv_yml_file_path }}"
  44. changed_when: true
  45. when: "'awx-projects-pv' not in k8s_pvs.stdout"
  46. - name: Create persistent volume for postgres
  47. command: "kubectl apply -f {{ awx_postgres_pv_file_path }}"
  48. changed_when: true
  49. when: "'awx-postgres-pv' not in k8s_pvs.stdout"
  50. - name: Get the docker images
  51. command: buildah images
  52. changed_when: false
  53. register: docker_images
  54. - name: Build the custom-awx-ee image from the docker file (It may take 5-10min)
  55. command: "buildah bud -t custom-awx-ee {{ awx_ee_docker_file }}"
  56. changed_when: false
  57. when: "'custom-awx-ee' not in docker_images.stdout"
  58. - name: Waiting for awx-operator deployment to be up and running
  59. command: kubectl wait --for=condition=available deployment awx-operator -n {{ awx_namespace }} --timeout=600s
  60. changed_when: false
  61. - name: Deploy awx
  62. command: "kubectl apply -f {{ awx_yml_file_path }}"
  63. changed_when: true
  64. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  65. - name: Install awxkit using pip3
  66. pip:
  67. name: awxkit
  68. state: present
  69. - name: Install awx collection
  70. command: "ansible-galaxy collection install awx.awx:{{ awx_version }}"
  71. changed_when: true
  72. register: installation_status
  73. - name: Wait for awx pods to get created
  74. wait_for:
  75. timeout: "{{ awx_wait_time }}"
  76. when: not k8s_pods.stdout | regex_search('awx-([A-Za-z0-9]{10})-([A-Za-z0-9]{5})')
  77. - name: Fails if the pods go into ImagePullBackOff state
  78. block:
  79. - name: Waiting for awx deployment to be up and running
  80. command: kubectl wait --for=condition=available deployment awx -n {{ awx_namespace }} --timeout=1200s
  81. changed_when: false
  82. rescue:
  83. - name: Display failure message
  84. debug:
  85. msg: "{{ deployment_failure_msg }}"