Skip to content

Commit d7f2126

Browse files
authored
feat: registrations.yaml: Retry failed registrations (when method == 'clients_host-registration')
Retry installation when using the `clients_host-registration` method: - A default of '3' forks will be used to avoid to overwhelm the Satellite server - These installations won't appear in the official "installation numbers": they'll be logged in different log files
1 parent 028c8d7 commit d7f2126

File tree

1 file changed

+52
-4
lines changed

1 file changed

+52
-4
lines changed

playbooks/tests/registrations.yaml

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
method: "clients.yaml"
1010
size: 10 # TODO: would be nice to provide total expected number and that would be divided by number of container hosts
1111
resting: 0
12+
num_retry_forks: 3
1213
registration_logs: "registration_logs"
1314
tasks:
1415
- name: "Check whether we have already registered some containers"
@@ -41,10 +42,15 @@
4142
shell:
4243
head -n "{{ containers_used_count|int + size|int }}" /root/container-ips.shuffled | tail -n "{{ size }}" | cut -d ' ' -f 2 > clients.ini
4344

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
4854

4955
- name: "Download host registration script from Satellite"
5056
ansible.builtin.get_url:
@@ -172,6 +178,48 @@
172178
line: "{{ containers_used_count|int + size|int }}"
173179
create: yes
174180

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+
175223
- name: "Give server some time to rest"
176224
pause:
177225
seconds: "{{ resting }}"

0 commit comments

Comments
 (0)