group_inventory.yml 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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: Get the hosts in node_inventory
  16. command: >-
  17. awx --conf.host {{ awx_host }} --conf.username {{ awx_admin_user }} --conf.password {{ awx_password }}
  18. --conf.insecure hosts list --inventory {{ node_inventory }} -f human --filter "name"
  19. changed_when: false
  20. no_log: true
  21. register: hosts_list
  22. - name: Add the host to compute group in node_inventory if it exists
  23. awx.awx.tower_group:
  24. name: "{{ item.split(',')[3] }}"
  25. inventory: "{{ node_inventory }}"
  26. preserve_existing_hosts: true
  27. hosts:
  28. - "{{ item.split(',')[2] }}"
  29. tower_config_file: "{{ tower_config_file }}"
  30. when:
  31. - item.split(',')[2] != "IP"
  32. - item.split(',')[2] in hosts_list.stdout
  33. - item.split(',')[3] == "compute"
  34. - name: Add the host to other groups in node_inventory if it exists
  35. awx.awx.tower_group:
  36. name: "{{ item.split(',')[3] }}"
  37. inventory: "{{ node_inventory }}"
  38. hosts:
  39. - "{{ item.split(',')[2] }}"
  40. tower_config_file: "{{ tower_config_file }}"
  41. when:
  42. - item.split(',')[2] != "IP"
  43. - item.split(',')[2] in hosts_list.stdout
  44. - item.split(',')[3] != "compute"