get_node_inventory.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. - name: Get inventory details
  16. block:
  17. - name: Copy slurm telemetry code
  18. copy:
  19. src: "{{ role_path }}/files/monster"
  20. dest: "{{ slurm_telemetry_code_dir }}"
  21. mode: "{{ slurm_telemetry_code_dir_mode }}"
  22. - name: Install sshpass
  23. package:
  24. name: sshpass
  25. state: present
  26. - name: Install jmepath
  27. pip:
  28. name: jmespath
  29. state: present
  30. executable: pip3
  31. - name: Get AWX service IP
  32. command: kubectl get svc awx-ui -n {{ awx_namespace }} -o=jsonpath='{.spec.clusterIP}'
  33. changed_when: false
  34. failed_when: false
  35. register: awx_svc_ip
  36. - name: AWX needs to be installed
  37. fail:
  38. msg: "{{ awx_fail_msg }}"
  39. when: not awx_svc_ip.stdout
  40. - name: Get AWX service port
  41. command: kubectl get svc awx-ui -n {{ awx_namespace }} -o=jsonpath='{.spec.ports[0].port}'
  42. changed_when: false
  43. register: awx_svc_port
  44. - name: Get AWX secret
  45. shell: >
  46. set -o pipefail && \
  47. kubectl get secret awx-admin-password -n {{ awx_namespace }} -o jsonpath="{.data.password}" | base64 --decode
  48. changed_when: false
  49. register: awx_secret
  50. - name: Get node_inventory id
  51. shell: >
  52. set -o pipefail && \
  53. awx --conf.host http://{{ awx_svc_ip.stdout }}:{{ awx_svc_port.stdout }} --conf.username {{ awx_username }} \
  54. --conf.password {{ awx_secret.stdout }} --conf.insecure inventory list -f human | grep node_inventory
  55. changed_when: false
  56. register: inventory_id
  57. - name: Node inventory not found in AWX
  58. fail:
  59. msg: "{{ node_inventory_fail_msg }}"
  60. when: not inventory_id.stdout
  61. - name: Get node_inventory
  62. command: awx --conf.host http://{{ awx_svc_ip.stdout }}:{{ awx_svc_port.stdout }} --conf.username {{ awx_username }} \
  63. --conf.password {{ awx_secret.stdout }} --conf.insecure hosts list --inventory {{ inventory_id.stdout[0] }}
  64. changed_when: false
  65. register: node_inventory_output
  66. - name: Save the json data
  67. set_fact:
  68. node_inventory_jsondata: "{{ node_inventory_output.stdout | from_json }}"
  69. - name: Add temporary hosts
  70. add_host:
  71. name: "{{ node_inventory_jsondata['results'][node_index].name }}"
  72. groups: "{{ node_inventory_jsondata['results'][node_index].summary_fields.groups.results[0].name }}"
  73. ansible_user: "{{ os_username }}"
  74. ansible_password: "{{ provision_password }}"
  75. ansible_become_pass: "{{ provision_password }}"
  76. ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
  77. with_items: "{{ node_inventory_jsondata['results'] }}"
  78. loop_control:
  79. index_var: node_index
  80. when: node_inventory_jsondata['results'][node_index].summary_fields.groups.count > 0
  81. no_log: true
  82. - name: Copy input_config file
  83. copy:
  84. src: "{{ role_path }}/files/input_config.yml"
  85. dest: "{{ role_path }}/files/monster/config.yml"
  86. mode: "{{ monster_config_file_mode }}"
  87. when: slurm_telemetry_support