initiate_telemetry.yml 11 KB

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