|
118 | 118 | run_once: true |
119 | 119 |
|
120 | 120 | - name: Get current nodes in Switch |
121 | | - shell: "cat {{ slurm_conf_path }}/topology.conf | grep \"{{item}}\" | grep Nodes= | awk '{ print $2}' | cut -c 7- | tr '\n' ',' | sed 's/,$/\\n/'" |
| 121 | + shell: "cat {{ slurm_conf_path }}/topology.conf | grep \"{{item}}\" | grep Nodes=" |
122 | 122 | register: nodes_in_switch |
123 | 123 | delegate_to: 127.0.0.1 |
124 | 124 | run_once: true |
125 | 125 | with_items: "{{racks_to_add}}" |
| 126 | + ignore_errors: yes |
126 | 127 |
|
127 | | -- name: Get hostlist |
128 | | - vars: |
129 | | - new_line: "{{item.stdout}}{% if item.stdout != ''%},{% endif%}{% for node in ( play_hosts | difference(groups['bastion']) | difference(groups['slurm_backup']) ) %}{% if hostvars[node]['rackID'] == item.item.split(':')[1] and (not ((hostvars[node]['ansible_hostname'] in item.stdout.split(',')|list)|bool)) %}{{hostvars[node]['ansible_hostname']}},{% endif %}{% endfor %}" |
130 | | - command: "scontrol show hostlistsorted {{new_line[:-1]}}" |
131 | | - register: rack_hostlist |
| 128 | +- name: Get current nodes in Switch hostlist |
| 129 | + vars: |
| 130 | + - switch_list_condensed: "{{item.stdout.split('Nodes=')[1]}}" |
| 131 | + command: "scontrol show hostname {{switch_list_condensed }}" |
| 132 | + register: switch_hostlist |
132 | 133 | delegate_to: 127.0.0.1 |
133 | 134 | with_items: "{{nodes_in_switch.results}}" |
| 135 | + when: item.rc == 0 |
| 136 | + |
| 137 | +- name: Get hostlist if switch exists |
| 138 | + vars: |
| 139 | + new_line: "{% for node in ( play_hosts | difference(groups['bastion']) | difference(groups['slurm_backup']) ) %}{% if cluster_name+':'+hostvars[node]['rackID'] == item.item.item %}{{hostvars[node]['ansible_hostname']}},{% endif %}{% endfor %}" |
| 140 | + command: "scontrol show hostlistsorted {{ item.stdout_lines | union (new_line[:-1].split(',') | list )| join(',') }}" |
| 141 | + register: rack_hostlist1 |
| 142 | + delegate_to: 127.0.0.1 |
| 143 | + with_items: "{{switch_hostlist.results}}" |
| 144 | + run_once: true |
| 145 | + when: item.item.rc == 0 |
| 146 | + |
| 147 | +- name: Get hostlist if switch does not exists |
| 148 | + vars: |
| 149 | + new_line: "{% for node in ( play_hosts | difference(groups['bastion']) | difference(groups['slurm_backup']) ) %}{% if cluster_name+':'+hostvars[node]['rackID'] == item.item.item %}{{hostvars[node]['ansible_hostname']}},{% endif %}{% endfor %}" |
| 150 | + command: "scontrol show hostlistsorted {{ new_line[:-1] }}" |
| 151 | + register: rack_hostlist2 |
| 152 | + delegate_to: 127.0.0.1 |
| 153 | + with_items: "{{switch_hostlist.results}}" |
| 154 | + run_once: true |
| 155 | + when: item.item.rc > 0 |
| 156 | + |
| 157 | +- name: get Nodes on switch |
| 158 | + set_fact: |
| 159 | + nodes_on_switches: "{{nodes_on_switches | default({}) | combine({item.item.item.item : item.stdout } ) }}" |
| 160 | + with_items: "{{rack_hostlist1.results}}" |
134 | 161 | run_once: true |
| 162 | + delegate_to: 127.0.0.1 |
| 163 | + when: item.item.item.rc== 0 |
135 | 164 |
|
| 165 | +- name: get Nodes on switch |
| 166 | + set_fact: |
| 167 | + nodes_on_switches: "{{nodes_on_switches | default({}) | combine({item.item.item.item : item.stdout } ) }}" |
| 168 | + with_items: "{{rack_hostlist2.results}}" |
| 169 | + run_once: true |
| 170 | + delegate_to: 127.0.0.1 |
| 171 | + when: item.item.item.rc > 0 |
| 172 | + |
136 | 173 | - name: Add the nodes in the rack switches |
137 | 174 | become: true |
138 | 175 | lineinfile: |
139 | 176 | path: "{{ slurm_conf_path }}/topology.conf" |
140 | 177 | regexp: "SwitchName={{item.item.item}}\\sNodes.*" |
141 | | - line: "SwitchName={{item.item.item}} Nodes={{item.stdout}}" |
| 178 | + line: "SwitchName={{item.item.item}} Nodes={{nodes_on_switches[item.item.item]}}" |
142 | 179 | state: present |
143 | 180 | run_once: true |
144 | | - with_items: "{{rack_hostlist.results}}" |
| 181 | + with_items: "{{switch_hostlist.results}}" |
145 | 182 | delegate_to: 127.0.0.1 |
146 | 183 | notify: reconfigure slurm |
147 | 184 |
|
|
0 commit comments