group_inventory.yml 1.2 KB

1234567891011121314151617181920212223242526272829303132
  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 the group in node_inventory if present
  23. awx.awx.tower_group:
  24. name: "{{ item.split(',')[3] }}"
  25. inventory: "{{ node_inventory }}"
  26. hosts:
  27. - "{{ item.split(',')[2] }}"
  28. tower_config_file: "{{ tower_config_file }}"
  29. when:
  30. - item.split(',')[2] != "IP"
  31. - item.split(',')[2] in hosts_list.stdout