add_host.yml 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: Initialise host description
  16. set_fact:
  17. host_description: "Description Unavailable"
  18. - name: Fetch description
  19. set_fact:
  20. host_description: "CPU:{{ hostvars[item]['ansible_processor_count'] }}
  21. Cores:{{ hostvars[item]['ansible_processor_cores'] }}
  22. Memory:{{ hostvars[item]['ansible_memtotal_mb'] }}MB
  23. BIOS:{{ hostvars[item]['ansible_bios_version'] }}"
  24. ignore_errors: yes
  25. - name: Fetch the hosts in awx node inventory
  26. command: >-
  27. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  28. --conf.insecure hosts list --inventory node_inventory
  29. changed_when: false
  30. no_log: true
  31. when:
  32. - host_description != "Description Unavailable"
  33. register: hosts
  34. ignore_errors: yes
  35. - name: Add the host to awx node inventory if not present
  36. command: >-
  37. awx --conf.host {{ awx_host }} --conf.username {{ awx_username }} --conf.password {{ awx_password }}
  38. --conf.insecure hosts create --name {{ item }} --inventory node_inventory
  39. changed_when: true
  40. when: item not in hosts.stdout
  41. no_log: true
  42. ignore_errors: yes
  43. - name: Host added msg
  44. debug:
  45. msg: "{{ host_added_msg + item }}"
  46. when:
  47. - host_description != "Description Unavailable"