test_prepare.yml 4.4 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. - block:
  16. - name: Get awx-service Cluster-IP
  17. command: "kubectl get svc awx-service -n {{ awx_namespace }} -o jsonpath='{.spec.clusterIP}'"
  18. register: awx_cluster_ip
  19. changed_when: false
  20. - name: Get AWX admin password
  21. shell: "kubectl get secret awx-admin-password -n {{ awx_namespace }} -o jsonpath='{.data.password}' | base64 --decode"
  22. register: awx_admin_password
  23. changed_when: false
  24. - name: Set IP and password
  25. set_fact:
  26. awx_ip: 'http://{{ awx_cluster_ip.stdout }}'
  27. admin_password: "{{ awx_admin_password.stdout }}"
  28. no_log: true
  29. - name: Check if {{ tower_config_file_path }} file is encrypted
  30. command: cat {{ tower_config_file_path }}
  31. changed_when: false
  32. no_log: true
  33. register: config_content
  34. run_once: true
  35. - name: Decrpyt {{ tower_config_file_path }}
  36. command: >-
  37. ansible-vault decrypt {{ tower_config_file_path }}
  38. --vault-password-file {{ tower_vault_file_path }}
  39. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  40. no_log: true
  41. changed_when: false
  42. run_once: true
  43. - name: Change tower_config file permissions
  44. file:
  45. path: "{{ tower_config_file_path }}"
  46. mode: "{{ file_perm }}"
  47. - name: Create an inventory
  48. tower_inventory:
  49. name: "{{ inventory_name }}"
  50. organization: "{{ organization_name }}"
  51. tower_config_file: "{{ tower_config_file_path }}"
  52. state: present
  53. - name: Create a host with inventory_hostname
  54. tower_host:
  55. name: "{{ inventory_hostname }}"
  56. inventory: "{{ inventory_name }}"
  57. state: present
  58. tower_config_file: "{{ tower_config_file_path }}"
  59. when: inventory_hostname is defined
  60. - name: Create a job template
  61. awx.awx.tower_job_template:
  62. name: "{{ job_template_name }}"
  63. job_type: "run"
  64. organization: "{{ organization_name }}"
  65. inventory: "{{ inventory_name }}"
  66. project: "{{ project_name }}"
  67. playbook: "{{ playbook_path }}"
  68. credentials:
  69. - "{{ item.credential }}"
  70. state: present
  71. tower_config_file: "{{ tower_config_file_path }}"
  72. loop: "{{ job_template_details }}"
  73. when: item.name == template_name
  74. - name: Change file permissions
  75. file:
  76. path: "../input_params/login_vars.yml"
  77. owner: root
  78. mode: "{{ file_perm }}"
  79. - name: Launch a job
  80. awx.awx.tower_job_launch:
  81. job_template: "{{ job_template_name }}"
  82. wait: yes
  83. tower_config_file: "{{ tower_config_file_path }}"
  84. failed_when: false
  85. register: job_status
  86. - name: Delete host created with inventory_hostname
  87. tower_host:
  88. name: "{{ inventory_hostname }}"
  89. inventory: "{{ inventory_name }}"
  90. state: absent
  91. tower_config_file: "{{ tower_config_file_path }}"
  92. when: inventory_hostname is defined
  93. - name: Delete an inventory
  94. tower_inventory:
  95. name: "{{ inventory_name }}"
  96. organization: "{{ organization_name }}"
  97. state: absent
  98. tower_config_file: "{{ tower_config_file_path }}"
  99. when: delete_status
  100. - name: Delete a job template
  101. awx.awx.tower_job_template:
  102. name: "{{ job_template_name }}"
  103. state: absent
  104. tower_config_file: "{{ tower_config_file_path }}"
  105. when: delete_status
  106. - name: Encrypt {{ tower_config_file_path }}
  107. command: >-
  108. ansible-vault encrypt {{ tower_config_file_path }}
  109. --vault-password-file {{ tower_vault_file_path }}
  110. changed_when: false
  111. - name: Change file permissions
  112. file:
  113. path: "{{ tower_config_file_path }}"
  114. owner: root
  115. mode: "{{ file_perm }}"
  116. rescue:
  117. - debug:
  118. msg: "{{ failed_msg }}"