provision_report.yml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright 2020 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. # This file used to generate a report of reachable and unreachable host of hpc cluster
  16. # This file can be executed only if provisioned_hosts.yml is created inside the path omnia/appliance/roles/inventory/files/provisioned_hosts.yml
  17. # Command to execute: ansible-playbook provision_report.yml -i ../roles/inventory/files/provisioned_hosts.yml
  18. - name: Find reachable hosts
  19. hosts: all
  20. gather_facts: false
  21. ignore_unreachable: true
  22. ignore_errors: true
  23. tasks:
  24. - name: Check for reachable nodes
  25. command: ping -c1 {{ inventory_hostname }}
  26. delegate_to: localhost
  27. register: ping_result
  28. ignore_errors: yes
  29. changed_when: false
  30. - name: Group reachable hosts
  31. group_by:
  32. key: "reachable"
  33. when: "'100% packet loss' not in ping_result.stdout"
  34. - name: Display hosts list
  35. hosts: localhost
  36. connection: local
  37. gather_facts: false
  38. tasks:
  39. - name: Set reachable and unreachable host number
  40. set_fact:
  41. reachable_host_number: "{{ groups['reachable'] | length}}"
  42. unreachable_host_number: "{{ groups['ungrouped'] | length}}"
  43. - name: Copy dhcpd.leases from cobbler
  44. command: docker cp cobbler:/var/lib/dhcpd/dhcpd.leases dhcpd.leases
  45. changed_when: true
  46. - name: Fetch ethernet details of unreachable hosts
  47. shell: sed -n '/{{ item }}/,/ethernet/p' dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  48. register: ethernet_detail_unreachable
  49. changed_when: false
  50. args:
  51. warn: no
  52. with_items:
  53. - "{{ groups['ungrouped'] }}"
  54. - name: Fetch ethernet details of reachable hosts
  55. shell: sed -n '/{{ item }}/,/ethernet/p' dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  56. register: ethernet_detail_reachable
  57. changed_when: false
  58. args:
  59. warn: no
  60. with_items:
  61. - "{{ groups['reachable'] }}"
  62. - name: Copy host information to file
  63. template:
  64. src: provision_host_report.j2
  65. dest: provision_host_report.txt
  66. - name: Read provision host report
  67. command: cat provision_host_report.txt
  68. register: host_report
  69. changed_when: false
  70. - name: Display provision host report
  71. debug:
  72. var: host_report.stdout_lines