|
9 | 9 | method: "clients.yaml"
|
10 | 10 | size: 10 # TODO: would be nice to provide total expected number and that would be divided by number of container hosts
|
11 | 11 | resting: 0
|
| 12 | + num_retry_forks: 3 |
12 | 13 | registration_logs: "registration_logs"
|
13 | 14 | tasks:
|
14 | 15 | - name: "Check whether we have already registered some containers"
|
|
41 | 42 | shell:
|
42 | 43 | head -n "{{ containers_used_count|int + size|int }}" /root/container-ips.shuffled | tail -n "{{ size }}" | cut -d ' ' -f 2 > clients.ini
|
43 | 44 |
|
44 |
| - - name: "Determine log name" |
45 |
| - set_fact: |
46 |
| - clients_yaml_cmd_log: "/root/out-{{ lookup('pipe', 'date --utc --iso-8601=seconds') | regex_replace('[^A-Za-z0-9-]', '_') }}.log" |
47 |
| - run_once: yes |
| 45 | + - name: "Set base log name" |
| 46 | + ansible.builtin.set_fact: |
| 47 | + clients_yaml_cmd_base: "/root/out-{{ lookup('pipe', 'date --utc --iso-8601=seconds') | regex_replace('[^A-Za-z0-9-]', '_') }}" |
| 48 | + run_once: true |
| 49 | + |
| 50 | + - name: "Set log name" |
| 51 | + ansible.builtin.set_fact: |
| 52 | + clients_yaml_cmd_log: "{{ clients_yaml_cmd_base }}.log" |
| 53 | + run_once: true |
48 | 54 |
|
49 | 55 | - name: "Download host registration script from Satellite"
|
50 | 56 | ansible.builtin.get_url:
|
|
172 | 178 | line: "{{ containers_used_count|int + size|int }}"
|
173 | 179 | create: yes
|
174 | 180 |
|
| 181 | + - name: "Get number of hosts that failed to register" |
| 182 | + ansible.builtin.command: |
| 183 | + cmd: "grep -c '^fatal: ' {{ clients_yaml_cmd_log }}" |
| 184 | + register: num_failed_hosts |
| 185 | + failed_when: num_failed_hosts.rc == 2 |
| 186 | + |
| 187 | + - name: "Show number of hosts that failed to register" |
| 188 | + ansible.builtin.debug: |
| 189 | + var: num_failed_hosts.stdout_lines |
| 190 | + |
| 191 | + - name: "Set additional retries log name (if needed)" |
| 192 | + ansible.builtin.set_fact: |
| 193 | + clients_yaml_cmd_retries_log: "{{ clients_yaml_cmd_base }}-retries.log" |
| 194 | + run_once: yes |
| 195 | + when: |
| 196 | + - num_failed_hosts.stdout_lines[0] | int > 0 |
| 197 | + - method == 'clients_host-registration' |
| 198 | + |
| 199 | + - name: "Try to re-register failed hosts (if needed)" |
| 200 | + ansible.builtin.shell: | |
| 201 | + cp -p {{ clients_yaml_cmd_log }} {{ clients_yaml_cmd_retries_log }} |
| 202 | +
|
| 203 | + while (( "$(grep -c '^fatal: ' {{ clients_yaml_cmd_retries_log }})" != 0 )); do |
| 204 | + unset CLIENT_IP_LIST |
| 205 | +
|
| 206 | + for client_ip in $(awk '/^fatal: / {print $2}' {{ clients_yaml_cmd_retries_log }} | cut -d'[' -f2 | cut -d']' -f1); do |
| 207 | + CLIENT_IP_LIST+="$client_ip," |
| 208 | + done |
| 209 | +
|
| 210 | + ansible-playbook \ |
| 211 | + --private-key /root/id_rsa_key \ |
| 212 | + --inventory $CLIENT_IP_LIST \ |
| 213 | + --forks "{{ num_retry_forks }}" \ |
| 214 | + clients_host-registration.yaml \ |
| 215 | + &> "{{ clients_yaml_cmd_retries_log }}" |
| 216 | + done |
| 217 | + register: clients_yaml_cmd_retries |
| 218 | + ignore_errors: true |
| 219 | + when: |
| 220 | + - num_failed_hosts.stdout_lines[0] | int > 0 |
| 221 | + - method == 'clients_host-registration' |
| 222 | + |
175 | 223 | - name: "Give server some time to rest"
|
176 | 224 | pause:
|
177 | 225 | seconds: "{{ resting }}"
|
|
0 commit comments