initiate_telemetry.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. # Include and initialize variables
  16. - name: Include telemetry_base_vars.yml
  17. include_vars: "{{ playbook_dir }}/input_params/telemetry_base_vars.yml"
  18. no_log: true
  19. - name: Include control_plane base_vars.yml file
  20. include_vars: "{{ playbook_dir }}/../control_plane/input_params/base_vars.yml"
  21. no_log: true
  22. - name: Initiate telemetry process if idrac_support is enabled
  23. block:
  24. - name: Include telemetry common vars
  25. include_vars: "{{ playbook_dir }}/roles/common/vars/main.yml"
  26. no_log: true
  27. - name: Include idrac-telemetry vars
  28. include_vars: "{{ playbook_dir }}/roles/idrac_telemetry/vars/main.yml"
  29. no_log: true
  30. - name: Include timescaledb vars
  31. include_vars: "{{ playbook_dir }}/roles/timescaledb/vars/main.yml"
  32. no_log: true
  33. - name: Initialize variables
  34. set_fact:
  35. tower_config_file: "{{ playbook_dir }}/../control_plane/roles/webui_awx/files/.tower_cli.cfg"
  36. tower_vault_file: "{{ playbook_dir }}/../control_plane/roles/webui_awx/files/.tower_vault_key"
  37. idrac_telemetry_scripting_repo: "https://github.com/dell/iDRAC-Telemetry-Scripting.git"
  38. idrac_telemetry_scripting_stable_commit: "1f4bb26"
  39. idrac_telemetry_scripting_folder: iDRAC-Telemetry-Scripting
  40. idrac_login_input_filename: "{{ playbook_dir }}/../control_plane/input_params/login_vars.yml"
  41. idrac_login_vault_filename: "{{ playbook_dir }}/../control_plane/input_params/.login_vault_key"
  42. login_vars_file: "{{ playbook_dir }}/input_params/telemetry_login_vars.yml"
  43. vault_filename: "{{ playbook_dir }}/input_params/.login_vault_key"
  44. min_firmware_version_reqd: 3
  45. datacenter_license: false
  46. firmware_version: false
  47. file_perm: '0644'
  48. telemetry_idrac: []
  49. service_type: 3
  50. auth_type: 1
  51. idrac_awx_count: 0
  52. filtered_idrac_count: 0
  53. failed_idrac: []
  54. awx_idrac: []
  55. # Get AWX Credentials from tower_config file
  56. - name: Check if tower_config file is encrypted
  57. command: cat {{ tower_config_file }}
  58. changed_when: false
  59. no_log: true
  60. register: config_content
  61. - name: Decrpyt tower_config
  62. command: >-
  63. ansible-vault decrypt {{ tower_config_file }}
  64. --vault-password-file {{ tower_vault_file }}
  65. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  66. changed_when: false
  67. - name: Change file permissions
  68. file:
  69. path: "{{ tower_config_file }}"
  70. mode: "{{ file_perm }}"
  71. - name: Fetch awx host
  72. command: grep "host:" "{{ tower_config_file }}"
  73. changed_when: false
  74. register: fetch_awx_host
  75. - name: Fetch awx username
  76. command: grep "username:" "{{ tower_config_file }}"
  77. register: fetch_awx_username
  78. changed_when: false
  79. no_log: true
  80. - name: Fetch awx password
  81. command: grep "password:" "{{ tower_config_file }}"
  82. changed_when: false
  83. no_log: true
  84. register: fetch_awx_password
  85. - name: Set awx variables
  86. set_fact:
  87. awx_host: "{{ fetch_awx_host.stdout | regex_replace('host: ','') }}"
  88. awx_username: "{{ fetch_awx_username.stdout | regex_replace('username: ','') }}"
  89. awx_password: "{{ fetch_awx_password.stdout | regex_replace('password: ','') }}"
  90. no_log: true
  91. - name: Encrypt tower_config_file
  92. command: >-
  93. ansible-vault encrypt {{ tower_config_file }}
  94. --vault-password-file {{ tower_vault_file }}
  95. changed_when: false
  96. - name: Change file permissions
  97. file:
  98. path: "{{ tower_config_file }}"
  99. mode: "{{ file_perm }}"
  100. # Get iDRAC inventory from AWX
  101. - name: Get idrac-inventory id
  102. shell: >-
  103. awx --conf.host "{{ awx_host }}" --conf.username "{{ awx_username }}" --conf.password "{{ awx_password }}" --conf.insecure
  104. inventory list -f human | grep idrac_inventory
  105. register: inventory_id
  106. changed_when: false
  107. - name: Get idrac host list
  108. command: >-
  109. awx --conf.host "{{ awx_host }}" --conf.username "{{ awx_username }}" --conf.password "{{ awx_password }}" --conf.insecure
  110. hosts list --inventory "{{ inventory_id.stdout[0] }}"
  111. register: idrac_inventory_output
  112. changed_when: false
  113. - name: Save the json data
  114. set_fact:
  115. idrac_inventory_jsondata: "{{ idrac_inventory_output.stdout | from_json }}"
  116. # Get iDRAC Credentials
  117. - name: Get iDRAC credentials
  118. block:
  119. - name: Check if {{ idrac_login_input_filename }} file is encrypted
  120. command: cat {{ idrac_login_input_filename }}
  121. changed_when: false
  122. no_log: true
  123. register: config_content
  124. - name: Decrpyt login_vars.yml
  125. command: >-
  126. ansible-vault decrypt {{ idrac_login_input_filename }}
  127. --vault-password-file {{ idrac_login_vault_filename }}
  128. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  129. changed_when: false
  130. - name: Include variable file {{ idrac_login_input_filename }}
  131. include_vars: "{{ idrac_login_input_filename }}"
  132. no_log: true
  133. - name: Encrypt login_vars.yml
  134. command: >-
  135. ansible-vault encrypt {{ idrac_login_input_filename }}
  136. --vault-password-file {{ idrac_login_vault_filename }}
  137. changed_when: false
  138. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  139. - name: Update login_vars.yml permission
  140. file:
  141. path: "{{ idrac_login_input_filename }}"
  142. mode: "{{ file_perm }}"
  143. when: idrac_inventory_jsondata['results'] is defined and (idrac_inventory_jsondata['results'] |length>0)
  144. # Get mysqldb credentials
  145. - name: Get mysqldb credentials
  146. block:
  147. - name: Check telemetry_login_vars file is encrypted
  148. command: cat {{ login_vars_file }}
  149. changed_when: false
  150. register: config_content
  151. # no_log: true
  152. - name: Decrpyt telemetry_login_vars.yml
  153. command: >-
  154. ansible-vault decrypt {{ login_vars_file }}
  155. --vault-password-file {{ vault_filename }}
  156. changed_when: false
  157. when: "'$ANSIBLE_VAULT;' in config_content.stdout"
  158. - name: Include variable file telemetry_login_vars.yml
  159. include_vars: "{{ login_vars_file }}"
  160. no_log: true
  161. - name: Encrypt input config file
  162. command: >-
  163. ansible-vault encrypt {{ login_vars_file }}
  164. --vault-password-file {{ vault_filename }}
  165. changed_when: false
  166. - name: Update telemetry_login_vars.yml permission
  167. file:
  168. path: "{{ login_vars_file }}"
  169. mode: "{{ file_perm }}"
  170. when: idrac_inventory_jsondata['results'] is defined and (idrac_inventory_jsondata['results'] |length>0)
  171. # Filter iDRACs matching telemtry pre-requisites
  172. - include_tasks: filter_idrac.yml
  173. with_items: "{{ idrac_inventory_jsondata['results'] }}"
  174. loop_control:
  175. index_var: idrac_index
  176. no_log: true
  177. # Add iDRAC Credentials in DB and enable telemetry fetching
  178. - name: Enable telemetry collection on iDRAC
  179. block:
  180. - name: Git clone telemetry initialization repo
  181. ansible.builtin.git:
  182. repo: "{{ idrac_telemetry_scripting_repo }}"
  183. dest: "{{ mount_location + idrac_telemetry_scripting_folder }}"
  184. version: "{{ idrac_telemetry_scripting_stable_commit }}"
  185. register: telemetry_collection
  186. - name: Enable telemetry collection on iDRACs
  187. command: python3 ./ConfigurationScripts/EnableOrDisableAllTelemetryReports.py -ip "{{ item }}" -u "{{ idrac_username }}" -p "{{ idrac_password }}" -s Enabled
  188. args:
  189. chdir: "{{ mount_location + idrac_telemetry_scripting_folder }}"
  190. with_items: "{{ telemetry_idrac }}"
  191. changed_when: false
  192. no_log: true
  193. when: telemetry_idrac is defined and (telemetry_idrac |length>0)
  194. rescue:
  195. - name: Show failure msg
  196. debug:
  197. msg: "Enabling telemetry on an iDRAC failed"
  198. - name: Add iDRAC details in mysqldb
  199. block:
  200. - name: Wait for mysqldb pod to come to ready state
  201. command: kubectl wait --for=condition=ready --timeout=10m -n "{{ namespace }}" pod -l app="{{ mysqldb_k8s_name }}"
  202. changed_when: false
  203. - name: Get mysqlDB svc IP
  204. command: kubectl get svc "{{ mysqldb_k8s_name }}" -n "{{ namespace }}" -o=jsonpath='{.spec.clusterIP}'
  205. changed_when: false
  206. register: mysql_svc_ip
  207. - name: Get mysqlDB svc port
  208. command: kubectl get svc "{{ mysqldb_k8s_name }}" -n "{{ namespace }}" -o=jsonpath='{.spec.ports[0].port}'
  209. changed_when: false
  210. register: mysql_svc_port
  211. - name: Add iDRAC host in mysqlDB
  212. community.mysql.mysql_query:
  213. login_host: "{{ mysql_svc_ip.stdout }}"
  214. login_port: "{{ mysql_svc_port.stdout }}"
  215. login_user: "{{ mysqldb_user }}"
  216. login_password: "{{ mysqldb_password }}"
  217. login_db: "{{ mysqldb_name }}"
  218. query: INSERT IGNORE INTO {{ mysqldb_name + '.services' }} (ip, serviceType, authType, auth) VALUES (%s, %s, %s ,'{"password":"{{ idrac_password | quote }}","username":"{{ idrac_username | quote }}"}')
  219. positional_args:
  220. - "{{ item }}"
  221. - "{{ service_type }}"
  222. - "{{ auth_type }}"
  223. with_items: "{{ telemetry_idrac }}"
  224. no_log: true
  225. when: telemetry_idrac is defined and (telemetry_idrac |length>0)
  226. rescue:
  227. - name: Show failure msg
  228. fail:
  229. msg: "Adding iDRAC credential details to mysqldb failed."
  230. # Initiate iDRAC collection
  231. - name: Initiate telemetry collection
  232. block:
  233. - name: Wait for idrac-telemetry pod to come to ready state
  234. command: kubectl wait --for=condition=ready --timeout=10m -n "{{ namespace }}" pod -l app="{{ idrac_telemetry_k8s_name }}"
  235. changed_when: false
  236. - name: Get idrac-telemetry pod name
  237. command: kubectl get pods -n "{{ namespace }}" -l app="{{ idrac_telemetry_k8s_name }}" -o jsonpath="{.items[0].metadata.name}"
  238. changed_when: false
  239. register: idrac_telemetry_pod
  240. - name: Wait for 15 sec for mysqldb to be ready with updated values
  241. pause:
  242. seconds: 15
  243. - name: Initiate telemetry-collector
  244. shell: kubectl exec --stdin --tty "{{ idrac_telemetry_pod.stdout }}" -n "{{ namespace }}" -c telemetry-receiver -- nohup go run cmd/redfishread/redfishread.go &
  245. changed_when: false
  246. when: telemetry_idrac is defined and (telemetry_idrac |length>0)
  247. - name: Telemetry report
  248. debug:
  249. msg:
  250. - "Count of iDRAC IPs found on AWX: {{ idrac_awx_count }}"
  251. - "List of iDRAC IPs found on AWX: {{ awx_idrac }}"
  252. - "Count of iDRAC IPs where telemetry is initiated: {{ filtered_idrac_count }}"
  253. - "List of iDRAC IPs where telemetry is initiated: {{ telemetry_idrac }}"
  254. when: idrac_telemetry_support is true