main.yml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. - 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: Copy dhcpd.leases from cobbler
  41. command: docker cp cobbler:/var/lib/dhcpd/dhcpd.leases {{ role_path}}/files/dhcpd.leases
  42. changed_when: true
  43. - name: Fetch ethernet details of unreachable hosts
  44. shell: sed -n '/{{ item }}/,/ethernet/p' {{ role_path}}/files/dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  45. register: ethernet_detail_unreachable_ping
  46. changed_when: false
  47. args:
  48. warn: no
  49. with_items:
  50. - "{{ groups['ungrouped'] }}"
  51. - name: Fetch ethernet details of unreachable hosts
  52. shell: sed -n '/{{ item }}/,/ethernet/p' {{ role_path}}/files/dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  53. register: ethernet_detail_unreachable_ssh
  54. changed_when: false
  55. args:
  56. warn: no
  57. when: groups['unreachable_ssh'] is defined
  58. with_items:
  59. - "{{ groups['unreachable_ssh'] }}"
  60. - name: Fetch ethernet details of reachable hosts
  61. shell: sed -n '/{{ item }}/,/ethernet/p' {{ role_path}}/files/dhcpd.leases | grep "ethernet" | awk '{ print $3 }' | uniq
  62. register: ethernet_detail_reachable
  63. changed_when: false
  64. args:
  65. warn: no
  66. when: groups['reachable_ssh'] is defined
  67. with_items:
  68. - "{{ groups['reachable_ssh'] }}"
  69. - name: Copy host information to file
  70. template:
  71. src: provision_host_report.j2
  72. dest: "{{ role_path}}/files/provision_host_report.txt"
  73. - name: Read provision host report
  74. command: cat {{ role_path}}/files/provision_host_report.txt
  75. register: host_report
  76. changed_when: false
  77. - name: Display provision host report
  78. debug:
  79. var: host_report.stdout_lines