awx_configuration.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. - name: Check if {{ tower_config_file }} file is encrypted
  16. command: cat {{ tower_config_file }}
  17. changed_when: false
  18. no_log: true
  19. register: config_content
  20. run_once: true
  21. - name: Decrpyt {{ tower_config_file }}
  22. command: >-
  23. ansible-vault decrypt {{ tower_config_file }}
  24. --vault-password-file {{ tower_vault_file }}
  25. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  26. changed_when: false
  27. run_once: true
  28. # Deleting the defaults
  29. - name: Delete machine credential
  30. awx.awx.tower_credential:
  31. name: "{{ default_credential }}"
  32. credential_type: "{{ default_credential_type }}"
  33. state: absent
  34. tower_config_file: "{{ tower_config_file }}"
  35. register: delete_credential
  36. until: not delete_credential.failed
  37. retries: "{{ max_retries }}"
  38. delay: "{{ max_delay }}"
  39. - name: Delete job template
  40. awx.awx.tower_job_template:
  41. name: "{{ default_template }}"
  42. state: absent
  43. tower_config_file: "{{ tower_config_file }}"
  44. - name: Delete project
  45. awx.awx.tower_project:
  46. name: "{{ default_project }}"
  47. state: absent
  48. tower_config_file: "{{ tower_config_file }}"
  49. - name: Delete organization
  50. awx.awx.tower_organization:
  51. name: "{{ default_org }}"
  52. state: absent
  53. tower_config_file: "{{ tower_config_file }}"
  54. # Configuration begins
  55. - name: Create organization
  56. awx.awx.tower_organization:
  57. name: "{{ awx_organization }}"
  58. description: "Name of organization using this product"
  59. state: present
  60. tower_config_file: "{{ tower_config_file }}"
  61. register: add_organization
  62. until: not add_organization.failed
  63. retries: "{{ max_retries }}"
  64. delay: "{{ max_delay }}"
  65. - name: Create awx inventories
  66. awx.awx.tower_inventory:
  67. name: "{{ item.name }}"
  68. description: "{{ item.description }}"
  69. organization: "{{ awx_organization }}"
  70. state: present
  71. tower_config_file: "{{ tower_config_file }}"
  72. loop: "{{ inventory_names }}"
  73. when: item.flag
  74. - name: Add groups to node_inventory
  75. awx.awx.tower_group:
  76. name: "{{ item.name }}"
  77. description: "{{ item.description }}"
  78. inventory: "node_inventory"
  79. state: present
  80. tower_config_file: "{{ tower_config_file }}"
  81. loop: "{{ group_names }}"
  82. - name: Add project
  83. awx.awx.tower_project:
  84. name: "{{ project_name }}"
  85. description: "{{ project_description }}"
  86. organization: "{{ awx_organization }}"
  87. scm_type: manual
  88. local_path: "{{ role_path.split('/')[-4] }}"
  89. default_environment: custom-awx-ee
  90. state: present
  91. tower_config_file: "{{ tower_config_file }}"
  92. wait: yes
  93. register: add_project
  94. until: not add_project.failed
  95. retries: "{{ max_retries }}"
  96. delay: "{{ max_delay }}"
  97. - name: Add awx credentials
  98. awx.awx.tower_credential:
  99. name: "{{ item.name }}"
  100. organization: "{{ awx_organization }}"
  101. credential_type: "{{ item.type }}"
  102. inputs:
  103. username: "{{ item.username }}"
  104. password: "{{ item.password }}"
  105. state: present
  106. tower_config_file: "{{ tower_config_file }}"
  107. loop: "{{ credential_details }}"
  108. no_log: true
  109. changed_when: true
  110. when: item.flag
  111. - name: Create awx job templates for network devices, inventories, storage and idrac
  112. awx.awx.tower_job_template:
  113. name: "{{ item.name }}"
  114. job_type: "run"
  115. organization: "{{ awx_organization }}"
  116. inventory: "{{ item.inventory }}"
  117. project: "{{ project_name }}"
  118. playbook: "{{ item.playbook }}"
  119. credentials:
  120. - "{{ item.credential }}"
  121. state: present
  122. tower_config_file: "{{ tower_config_file }}"
  123. loop: "{{ job_template_details }}"
  124. when: item.flag
  125. - name: Create awx job template for deploying omnia
  126. awx.awx.tower_job_template:
  127. name: "{{ item.name }}"
  128. job_type: "run"
  129. organization: "{{ awx_organization }}"
  130. inventory: "{{ item.inventory }}"
  131. project: "{{ project_name }}"
  132. playbook: "{{ item.playbook }}"
  133. ask_skip_tags_on_launch: true
  134. extra_vars: "{{ item.extra_vars }}"
  135. credentials:
  136. - "{{ item.credential }}"
  137. state: present
  138. tower_config_file: "{{ tower_config_file }}"
  139. loop: "{{ omnia_job_template_details }}"
  140. - name: Build a schedule for node inventory and device inventory
  141. awx.awx.tower_schedule:
  142. name: "{{ item.name }}"
  143. unified_job_template: "{{ item.template }}"
  144. rrule: "{{ item.schedule_rule }}"
  145. state: present
  146. tower_config_file: "{{ tower_config_file }}"
  147. register: result
  148. loop: "{{ scheduled_templates }}"
  149. when: item.flag
  150. - name: Encrypt {{ tower_config_file }}
  151. command: >-
  152. ansible-vault encrypt {{ tower_config_file }}
  153. --vault-password-file {{ tower_vault_file }}
  154. changed_when: false
  155. - name: Change file permissions
  156. file:
  157. path: "{{ tower_config_file }}"
  158. mode: "{{ file_perm }}"