main.yml 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright 2021 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: Initialize reachable and unreachable host number
  16. set_fact:
  17. reachable_host_number: 0
  18. unreachable_host_number: 0
  19. unreachable_ssh_host_number: 0
  20. unreachable_ping_host_number: 0
  21. - name: Set reachable host number
  22. set_fact:
  23. reachable_host_number: "{{ groups['reachable_ssh'] | length}}"
  24. when: groups['reachable_ssh'] is defined
  25. - name: Set unreachable host number
  26. set_fact:
  27. unreachable_host_number: "{{ groups['ungrouped'] | length | int + groups['unreachable_ssh'] | length | int }}"
  28. unreachable_ssh_host_number: "{{ groups['unreachable_ssh'] | length }}"
  29. unreachable_ping_host_number: "{{ groups['ungrouped'] | length }}"
  30. when: groups['unreachable_ssh'] is defined
  31. - name: Set unreachable host number
  32. set_fact:
  33. unreachable_host_number: "{{ groups['ungrouped'] | length }}"
  34. unreachable_ping_host_number: "{{ groups['ungrouped'] | length }}"
  35. when: groups['unreachable_ssh'] is not defined
  36. - name: Create files folder
  37. file:
  38. path: "{{ role_path}}/files"
  39. state: directory
  40. - name: Fetch cobbler pod name
  41. command: kubectl get pods -n cobbler -o jsonpath="{.items[0].metadata.name}"
  42. register: cobbler_pod
  43. changed_when: false
  44. - name: Copy dhcpd.leases from cobbler
  45. command: kubectl cp {{ cobbler_pod.stdout }}:/var/lib/dhcpd/dhcpd.leases {{ role_path}}/files/dhcpd.leases -n cobbler
  46. changed_when: true
  47. - name: Fetch ethernet details of unreachable hosts
  48. shell: sed -n '/{{ item }}/,/ethernet/p' {{ role_path}}/files/dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  49. register: ethernet_detail_unreachable_ping
  50. changed_when: false
  51. args:
  52. warn: no
  53. with_items:
  54. - "{{ groups['ungrouped'] }}"
  55. - name: Fetch ethernet details of unreachable hosts
  56. shell: sed -n '/{{ item }}/,/ethernet/p' {{ role_path}}/files/dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  57. register: ethernet_detail_unreachable_ssh
  58. changed_when: false
  59. args:
  60. warn: no
  61. when: groups['unreachable_ssh'] is defined
  62. with_items:
  63. - "{{ groups['unreachable_ssh'] }}"
  64. - name: Fetch ethernet details of reachable hosts
  65. shell: sed -n '/{{ item }}/,/ethernet/p' {{ role_path}}/files/dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  66. register: ethernet_detail_reachable
  67. changed_when: false
  68. args:
  69. warn: no
  70. when: groups['reachable_ssh'] is defined
  71. with_items:
  72. - "{{ groups['reachable_ssh'] }}"
  73. - name: Copy host information to file
  74. template:
  75. src: provision_host_report.j2
  76. dest: "{{ role_path}}/files/provision_host_report.txt"
  77. - name: Read provision host report
  78. command: cat {{ role_path}}/files/provision_host_report.txt
  79. register: host_report
  80. changed_when: false
  81. - name: Display provision host report
  82. debug:
  83. var: host_report.stdout_lines