group_inventory.yml 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: Initializing variables
  16. set_fact:
  17. compute_list: []
  18. non_compute_list: []
  19. component_roles: []
  20. - name: Get the hosts in node_inventory
  21. command: awx --conf.host {{ awx_host }} --conf.username {{ awx_admin_user }} --conf.password {{ awx_password }} --conf.insecure hosts list --inventory {{ node_inventory }} -f human --filter "name"
  22. changed_when: false
  23. no_log: true
  24. register: hosts_list
  25. - name: Converting csv values to list
  26. read_csv:
  27. path: "{{ host_mapping_file_path }}"
  28. delimiter: ','
  29. register: mapping
  30. - name: Collecting compute node ip's from host mapping file
  31. set_fact:
  32. compute_list: "{{ compute_list + [ item.IP ] }}"
  33. when:
  34. - item.Component_role == compute_node
  35. - item.IP in hosts_list.stdout
  36. no_log: true
  37. with_items:
  38. - "{{ mapping.list }}"
  39. - name: Collecting manager,nfs_node,login_nodes ip's from host mapping file
  40. set_fact:
  41. non_compute_list: "{{ non_compute_list + [ item.IP ] }}"
  42. component_roles: "{{ component_roles + [item.Component_role] }}"
  43. when:
  44. - item.Component_role != compute_node
  45. no_log: true
  46. with_items:
  47. - "{{ mapping.list }}"
  48. - name: Adding ips to compute node in awx ui
  49. block:
  50. - name: Add the host to compute group in node_inventory if it exists
  51. awx.awx.tower_group:
  52. name: "{{ compute_node }}"
  53. inventory: "{{ node_inventory }}"
  54. hosts: "{{ compute_list }}"
  55. tower_config_file: "{{ tower_config_file }}"
  56. register: compute_output
  57. no_log: true
  58. rescue:
  59. - name: Failed to add ip's to compute node in awx ui
  60. fail:
  61. msg: "{{ compute_output.stdout }}"
  62. - name: Adding ips to manager,nfs_node,login_node in awx ui
  63. block:
  64. - name: Add the host to other groups in node_inventory if it exists
  65. awx.awx.tower_group:
  66. name: "{{ item.0 }}"
  67. inventory: "{{ node_inventory }}"
  68. hosts:
  69. - "{{ item.1 }}"
  70. tower_config_file: "{{ tower_config_file }}"
  71. when: item.1 in hosts_list.stdout
  72. with_together:
  73. - "{{ component_roles }}"
  74. - "{{ non_compute_list }}"
  75. register: non_compute_output
  76. no_log: true
  77. rescue:
  78. - name: Failed to add ip's to manager,nfs_node,login_node
  79. fail:
  80. msg: "{{ non_compute_output.stdout }}"