get_node_inventory.yml 2.9 KB

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