main.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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: Include provision_idrac vars
  16. include_vars: "{{ playbook_dir }}/../roles/provision_idrac/vars/main.yml"
  17. run_once: true
  18. - name: Check tower_cli.cfg is encrypted
  19. command: cat "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vars_filename }}"
  20. changed_when: false
  21. register: awx_content
  22. run_once: true
  23. - name: Decrpyt tower_cli.cfg
  24. command: >-
  25. ansible-vault decrypt "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vars_filename }}"
  26. --vault-password-file "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vaultname }}"
  27. changed_when: false
  28. run_once: true
  29. when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
  30. - name: Fetch awx host
  31. command: grep "host:" "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vars_filename }}"
  32. register: fetch_awx_host
  33. changed_when: false
  34. run_once: true
  35. - name: Fetch awx username
  36. command: grep "username:" "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vars_filename }}"
  37. register: fetch_awx_username
  38. changed_when: false
  39. run_once: true
  40. no_log: true
  41. - name: Fetch awx password
  42. command: grep "password:" "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vars_filename }}"
  43. register: fetch_awx_password
  44. changed_when: false
  45. run_once: true
  46. no_log: true
  47. - name: Set awx variables
  48. set_fact:
  49. awx_host: "{{ fetch_awx_host.stdout | regex_replace('host: ','') }}"
  50. awx_username: "{{ fetch_awx_username.stdout | regex_replace('username: ','') }}"
  51. awx_password: "{{ fetch_awx_password.stdout | regex_replace('password: ','') }}"
  52. no_log: true
  53. - name: Encrypt tower_cli.cfg
  54. command: >-
  55. ansible-vault encrypt "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vars_filename }}"
  56. --vault-password-file "{{ playbook_dir }}/../roles/webui_awx/files/{{ awx_vaultname }}"
  57. changed_when: false
  58. run_once: true
  59. when: "'$ANSIBLE_VAULT;' in awx_content.stdout"
  60. - name: Get inventory list
  61. command: >-
  62. awx --conf.host "{{ awx_host }}" --conf.username "{{ awx_username }}" --conf.password "{{ awx_password }}"
  63. inventory list -f human --filter "name"
  64. register: inventory_list
  65. run_once: true
  66. changed_when: false
  67. no_log: true
  68. - block:
  69. - name: Fetch provisioned_idrac inventory
  70. command: >-
  71. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  72. hosts list --inventory "{{ provisioned_idrac_inventory_name }}" -f human --filter "name"
  73. register: fetch_inventory
  74. run_once: true
  75. changed_when: false
  76. no_log: true
  77. - name: Launch ethernet_template
  78. command: >-
  79. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  80. job_templates launch {{ ethernet_template_name }} --wait
  81. run_once: true
  82. changed_when: true
  83. no_log: true
  84. - name: Wait for 10 mins for DHCP to assign IP to devices
  85. wait_for:
  86. timeout: "{{ dhcp_wait_time }}"
  87. - name: Launch idrac_template
  88. command: >-
  89. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  90. job_templates launch {{ idrac_template_name }} --wait
  91. run_once: true
  92. changed_when: false
  93. no_log: true
  94. when: inventory_hostname not in fetch_inventory.stdout
  95. when: provisioned_idrac_inventory_name in inventory_list.stdout