awx_configuration.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. # Copyright 2020 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: Waiting for 30 seconds for UI components to be accessible
  17. wait_for:
  18. timeout: 30
  19. - name: Organization list
  20. block:
  21. - name: Get organization list
  22. command: >-
  23. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  24. organizations list -f human
  25. register: organizations_list
  26. changed_when: no
  27. no_log: True
  28. rescue:
  29. - name: Message
  30. fail:
  31. msg: "{{ organizations_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  32. - name: Project list
  33. block:
  34. - name: Get project list
  35. command: >-
  36. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  37. projects list -f human
  38. register: projects_list
  39. changed_when: no
  40. no_log: True
  41. rescue:
  42. - name: Message
  43. fail:
  44. msg: "{{ projects_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  45. - name: Inventory list
  46. block:
  47. - name: Get inventory list
  48. command: >-
  49. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  50. inventory list -f human
  51. register: inventory_list
  52. changed_when: no
  53. no_log: True
  54. rescue:
  55. - name: Message
  56. fail:
  57. msg: "{{ inventory_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  58. - name: Credential list
  59. block:
  60. - name: Get credentials list
  61. command: >-
  62. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  63. credentials list -f human
  64. register: credentials_list
  65. changed_when: no
  66. no_log: True
  67. rescue:
  68. - name: Message
  69. fail:
  70. msg: "{{ credentials_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  71. - name: Template List
  72. block:
  73. - name: Get template list
  74. command: >-
  75. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  76. job_templates list -f human
  77. register: job_templates_list
  78. changed_when: no
  79. no_log: True
  80. rescue:
  81. - name: Message
  82. fail:
  83. msg: "{{ job_templates_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  84. - name: Group names
  85. block:
  86. - name: If omnia-inventory exists, fetch group names in the inventory
  87. command: >-
  88. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  89. groups list --inventory "{{ omnia_inventory_name }}" -f human
  90. register: groups_list
  91. when: omnia_inventory_name in inventory_list.stdout
  92. no_log: True
  93. rescue:
  94. - name: Message
  95. fail:
  96. msg: "{{ groups_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  97. - name: Schedules list
  98. block:
  99. - name: Get schedules list
  100. command: >-
  101. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  102. schedules list -f human
  103. register: schedules_list
  104. changed_when: no
  105. no_log: True
  106. rescue:
  107. - name: Message
  108. fail:
  109. msg: "{{ schedules_list.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  110. # Delete Default Configurations
  111. - name: Delete default configurations
  112. block:
  113. - name: Delete default organization
  114. command: >-
  115. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  116. organizations delete "{{ default_org }}"
  117. when: default_org in organizations_list.stdout
  118. register: register_error
  119. no_log: True
  120. - name: Delete default job template
  121. command: >-
  122. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  123. job_templates delete "{{ default_template }}"
  124. when: default_template in job_templates_list.stdout
  125. register: register_error
  126. no_log: True
  127. - name: Delete default project
  128. command: >-
  129. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  130. projects delete "{{ default_projects }}"
  131. when: default_projects in projects_list.stdout
  132. register: register_error
  133. no_log: True
  134. - name: Delete default credential
  135. command: >-
  136. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  137. credentials delete "{{ default_credentials }}"
  138. when: default_credentials in credentials_list.stdout
  139. register: register_error
  140. no_log: True
  141. rescue:
  142. - name: Message
  143. fail:
  144. msg: "{{ register_error.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"
  145. # Create required configuration if not present
  146. - name: Create required configurations
  147. block:
  148. - name: Create organisation
  149. command: >-
  150. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  151. organizations create --name "{{ organization_name }}"
  152. when: organization_name not in organizations_list.stdout
  153. register: register_error
  154. no_log: True
  155. - name: Create new project
  156. command: >-
  157. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  158. projects create --name "{{ project_name }}" --organization "{{ organization_name }}"
  159. --local_path "{{ role_path.split('/')[-4] }}"
  160. when: project_name not in projects_list.stdout
  161. register: register_error
  162. no_log: True
  163. - name: Create new omnia inventory
  164. command: >-
  165. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  166. inventory create --name "{{ omnia_inventory_name }}" --organization "{{ organization_name }}"
  167. when: omnia_inventory_name not in inventory_list.stdout
  168. register: register_error
  169. no_log: True
  170. - name: Create groups in omnia inventory
  171. command: >-
  172. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  173. groups create --name "{{ item }}" --inventory "{{ omnia_inventory_name }}"
  174. when: omnia_inventory_name not in inventory_list.stdout or item not in groups_list.stdout
  175. register: register_error
  176. no_log: True
  177. loop: "{{ group_names }}"
  178. - name: Create credentials for omnia
  179. command: >-
  180. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  181. credentials create --name "{{ credential_name }}" --organization "{{ organization_name }}"
  182. --credential_type "{{ credential_type }}"
  183. --inputs '{"username": "{{ cobbler_username }}", "password": "{{ cobbler_password }}"}'
  184. when: credential_name not in credentials_list.stdout
  185. register: register_error
  186. no_log: True
  187. - name: DeployOmnia Template
  188. block:
  189. - name: Create template to deploy omnia
  190. command: >-
  191. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  192. job_templates create
  193. --name "{{ omnia_template_name }}"
  194. --job_type run
  195. --inventory "{{ omnia_inventory_name }}"
  196. --project "{{ project_name }}"
  197. --playbook "{{ omnia_playbook }}"
  198. --verbosity "{{ playbooks_verbosity }}"
  199. --ask_skip_tags_on_launch true
  200. register: register_error
  201. no_log: True
  202. - name: Associate credential
  203. command: >-
  204. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  205. job_templates associate "{{ omnia_template_name }}"
  206. --credential ""{{ credential_name }}""
  207. register: register_error
  208. no_log: True
  209. when: omnia_template_name not in job_templates_list.stdout
  210. - name: DynamicInventory template
  211. block:
  212. - name: Create template to fetch dynamic inventory
  213. command: >-
  214. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  215. job_templates create
  216. --name "{{ inventory_template_name }}"
  217. --job_type run
  218. --inventory "{{ omnia_inventory_name }}"
  219. --project "{{ project_name }}"
  220. --playbook "{{ inventory_playbook }}"
  221. --verbosity "{{ playbooks_verbosity }}"
  222. --use_fact_cache true
  223. register: register_error
  224. no_log: True
  225. - name: Associate credential
  226. command: >-
  227. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  228. job_templates associate "{{ inventory_template_name }}"
  229. --credential ""{{ credential_name }}""
  230. register: register_error
  231. no_log: True
  232. when: inventory_template_name not in job_templates_list.stdout
  233. - name: Schedule dynamic inventory template
  234. block:
  235. - name: Get unified job template list
  236. command: >-
  237. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  238. unified_job_templates list --name "{{ inventory_template_name }}" -f human
  239. no_log: True
  240. register: unified_job_template_list
  241. - name: Get job ID
  242. set_fact:
  243. job_id: "{{ unified_job_template_list.stdout | regex_search('[0-9]+') }}"
  244. - name: Schedule dynamic inventory job
  245. command: >-
  246. awx --conf.host "{{ awx_ip }}" --conf.username "{{ awx_user }}" --conf.password "{{ admin_password }}"
  247. schedules create --name "{{ schedule_name }}"
  248. --unified_job_template="{{ job_id }}" --rrule="{{ schedule_rule }}"
  249. register: register_error
  250. no_log: True
  251. when: schedule_name not in schedules_list.stdout
  252. rescue:
  253. - name: Message
  254. fail:
  255. msg: "{{ register_error.stdout | regex_replace(awx_user) | regex_replace(admin_password) }}"