configure_settings.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. # Get Current AWX configuration
  16. - name: Get the awx services
  17. command: "kubectl get svc -n {{ awx_namespace }}"
  18. changed_when: false
  19. register: awx_services
  20. - name: Expose the service for awx deployment on 8052 port
  21. command: "kubectl expose deployment awx --type=NodePort --name={{ awx_service_name }} --port={{ awx_port }} -n {{ awx_namespace }}"
  22. changed_when: false
  23. when: awx_service_name not in awx_services.stdout
  24. - name: Get awx-service Cluster-IP
  25. command: "kubectl get svc {{ awx_service_name }} -n {{ awx_namespace }} -o jsonpath='{.spec.clusterIP}'"
  26. register: awx_cluster_ip
  27. changed_when: false
  28. - name: Get AWX admin password
  29. shell: >
  30. set -o pipefail && \
  31. kubectl get secret awx-admin-password -n {{ awx_namespace }} -o jsonpath='{.data.password}' | base64 --decode
  32. no_log: true
  33. register: awx_admin_password
  34. changed_when: false
  35. - name: Check if config file exists
  36. stat:
  37. path: "{{ tower_config_file }}"
  38. register: config_file
  39. - name: Create tower config file
  40. copy:
  41. dest: "{{ tower_config_file }}"
  42. content: |
  43. [general]
  44. host: http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}
  45. username: admin
  46. password: {{ awx_admin_password.stdout }}
  47. verify_ssl: false
  48. use_token: false
  49. owner: root
  50. mode: "{{ file_perm }}"
  51. when: not config_file.stat.exists
  52. - name: Check if tower_vault_key exists
  53. stat:
  54. path: "{{ tower_vault_file }}"
  55. register: tower_vault
  56. - name: Create ansible vault key if it does not exist
  57. set_fact:
  58. tower_vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  59. when: not tower_vault.stat.exists
  60. - name: Save vault key
  61. copy:
  62. dest: "{{ tower_vault_file }}"
  63. content: |
  64. {{ tower_vault_key }}
  65. owner: root
  66. force: yes
  67. mode: "{{ vault_file_perm }}"
  68. when: not tower_vault.stat.exists
  69. - name: Check if {{ tower_config_file }} file is encrypted
  70. command: cat {{ tower_config_file }}
  71. changed_when: false
  72. no_log: true
  73. register: config_content
  74. run_once: true
  75. - name: Encrypt {{ tower_config_file }}
  76. command: >-
  77. ansible-vault encrypt {{ tower_config_file }}
  78. --vault-password-file {{ tower_vault_file }}
  79. changed_when: false
  80. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  81. run_once: true
  82. - name: Change file permissions
  83. file:
  84. path: "{{ tower_config_file }}"
  85. mode: "{{ file_perm }}"
  86. - name: Open awx TCP ports on the firewall
  87. firewalld:
  88. port: "{{ item }}/tcp"
  89. permanent: yes
  90. state: enabled
  91. with_items: "{{ awx_tcp_ports }}"
  92. - name: Masquerade the firewall
  93. firewalld:
  94. masquerade: yes
  95. permanent: yes
  96. state: enabled
  97. zone: public
  98. - name: Reload firewalld service
  99. systemd:
  100. name: firewalld
  101. state: reloaded
  102. - name: Waiting for AWX UI
  103. wait_for:
  104. host: "{{ awx_cluster_ip.stdout }}"
  105. port: "{{ awx_port }}"
  106. timeout: "{{ awx_ui_wait_time }}"
  107. - name: Waiting for the AWX UI to be up
  108. uri:
  109. url: "http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}"
  110. status_code: "{{ return_status }}"
  111. register: display
  112. until: display.status == 200
  113. retries: "{{ max_retries }}"
  114. delay: "{{ max_delay }}"
  115. changed_when: false
  116. - name: Waiting for the AWX UI to be in running state
  117. uri:
  118. url: "http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}"
  119. status_code: "{{ return_status }}"
  120. return_content: true
  121. register: display
  122. until: awx_ui_msg not in display.content
  123. retries: "{{ max_retries }}"
  124. delay: "{{ max_delay }}"
  125. changed_when: false