install_awx.yml 3.8 KB

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