awx_configuration.yml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. - 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. - name: Create awx inventories
  62. awx.awx.tower_inventory:
  63. name: "{{ item.name }}"
  64. description: "{{ item.description }}"
  65. organization: "{{ awx_organization }}"
  66. state: present
  67. tower_config_file: "{{ tower_config_file }}"
  68. loop: "{{ inventory_names }}"
  69. when: item.flag
  70. - name: Add groups to node_inventory
  71. awx.awx.tower_group:
  72. name: "{{ item.name }}"
  73. description: "{{ item.description }}"
  74. inventory: "node_inventory"
  75. state: present
  76. tower_config_file: "{{ tower_config_file }}"
  77. loop: "{{ group_names }}"
  78. - name: Add project
  79. awx.awx.tower_project:
  80. name: "{{ project_name }}"
  81. description: "{{ project_description }}"
  82. organization: "{{ awx_organization }}"
  83. scm_type: manual
  84. local_path: "{{ role_path.split('/')[-4] }}"
  85. default_environment: custom-awx-ee
  86. state: present
  87. tower_config_file: "{{ tower_config_file }}"
  88. - name: Add awx credentials
  89. awx.awx.tower_credential:
  90. name: "{{ item.name }}"
  91. organization: "{{ awx_organization }}"
  92. credential_type: "{{ item.type }}"
  93. inputs:
  94. username: "{{ item.username }}"
  95. password: "{{ item.password }}"
  96. state: present
  97. tower_config_file: "{{ tower_config_file }}"
  98. loop: "{{ credential_details }}"
  99. no_log: true
  100. changed_when: true
  101. when: item.flag
  102. - name: Create awx job templates for network devices, inventories, storage and idrac
  103. awx.awx.tower_job_template:
  104. name: "{{ item.name }}"
  105. job_type: "run"
  106. organization: "{{ awx_organization }}"
  107. inventory: "{{ item.inventory }}"
  108. project: "{{ project_name }}"
  109. playbook: "{{ item.playbook }}"
  110. credentials:
  111. - "{{ item.credential }}"
  112. state: present
  113. tower_config_file: "{{ tower_config_file }}"
  114. loop: "{{ job_template_details }}"
  115. when: item.flag
  116. - name: Create awx job template for deploying omnia
  117. awx.awx.tower_job_template:
  118. name: "{{ item.name }}"
  119. job_type: "run"
  120. organization: "{{ awx_organization }}"
  121. inventory: "{{ item.inventory }}"
  122. project: "{{ project_name }}"
  123. playbook: "{{ item.playbook }}"
  124. ask_skip_tags_on_launch: true
  125. credentials:
  126. - "{{ item.credential }}"
  127. state: present
  128. tower_config_file: "{{ tower_config_file }}"
  129. loop: "{{ omnia_job_template_details }}"
  130. - name: Build a schedule for idrac job template
  131. awx.awx.tower_schedule:
  132. name: "{{ item.name }}"
  133. unified_job_template: "{{ item.template }}"
  134. rrule: "{{ item.schedule_rule }}"
  135. state: present
  136. tower_config_file: "{{ tower_config_file }}"
  137. register: result
  138. loop: "{{ scheduled_templates }}"
  139. - name: Encrypt {{ tower_config_file }}
  140. command: >-
  141. ansible-vault encrypt {{ tower_config_file }}
  142. --vault-password-file {{ tower_vault_file }}
  143. changed_when: false
  144. - name: Change file permissions
  145. file:
  146. path: "{{ tower_config_file }}"
  147. mode: "{{ file_perm }}"