install_awx.yml 4.1 KB

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