configure_settings.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. # 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. register: awx_admin_password
  33. changed_when: false
  34. - name: Check if config file exists
  35. stat:
  36. path: "{{ tower_config_file }}"
  37. register: config_file
  38. - name: Create tower config file
  39. copy:
  40. dest: "{{ tower_config_file }}"
  41. content: |
  42. [general]
  43. host: http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}
  44. username: admin
  45. password: {{ awx_admin_password.stdout }}
  46. verify_ssl: false
  47. use_token: false
  48. owner: root
  49. mode: "{{ file_perm }}"
  50. when: not config_file.stat.exists
  51. - name: Check if tower_vault_key exists
  52. stat:
  53. path: "{{ tower_vault_file }}"
  54. register: tower_vault
  55. - name: Create ansible vault key if it does not exist
  56. set_fact:
  57. tower_vault_key: "{{ lookup('password', '/dev/null chars=ascii_letters') }}"
  58. when: not tower_vault.stat.exists
  59. - name: Save vault key
  60. copy:
  61. dest: "{{ tower_vault_file }}"
  62. content: |
  63. {{ tower_vault_key }}
  64. owner: root
  65. force: yes
  66. mode: "{{ vault_file_perm }}"
  67. when: not tower_vault.stat.exists
  68. - name: Check if {{ tower_config_file }} file is encrypted
  69. command: cat {{ tower_config_file }}
  70. changed_when: false
  71. no_log: true
  72. register: config_content
  73. run_once: true
  74. - name: Encrypt {{ tower_config_file }}
  75. command: >-
  76. ansible-vault encrypt {{ tower_config_file }}
  77. --vault-password-file {{ tower_vault_file }}
  78. changed_when: false
  79. when: "'$ANSIBLE_VAULT;' not in config_content.stdout"
  80. run_once: true
  81. - name: Change file permissions
  82. file:
  83. path: "{{ tower_config_file }}"
  84. mode: "{{ file_perm }}"
  85. - name: Open awx TCP ports on the firewall
  86. firewalld:
  87. port: "{{ item }}/tcp"
  88. permanent: yes
  89. state: enabled
  90. with_items: "{{ awx_tcp_ports }}"
  91. - name: Masquerade the firewall
  92. firewalld:
  93. masquerade: yes
  94. permanent: yes
  95. state: enabled
  96. zone: public
  97. - name: Reload firewalld service
  98. systemd:
  99. name: firewalld
  100. state: reloaded
  101. - name: Waiting for the AWX UI to be up
  102. uri:
  103. url: "http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}"
  104. status_code: "{{ return_status }}"
  105. register: display
  106. until: display.status == 200
  107. retries: "{{ max_retries }}"
  108. delay: "{{ max_delay }}"
  109. changed_when: false
  110. - name: Waiting for the AWX UI to be in running state
  111. uri:
  112. url: "http://{{ awx_cluster_ip.stdout }}:{{ awx_port }}"
  113. status_code: "{{ return_status }}"
  114. return_content: true
  115. register: display
  116. until: awx_ui_msg not in display.content
  117. retries: "{{ max_retries }}"
  118. delay: "{{ max_delay }}"
  119. changed_when: false