Hello.
Thx. for your reply.
Changed the IPs as suggested. Yes I see it easier.
What I see from the execution above is, after the 'force a failure' the debug task is also executed. I understood the rescue section should be executed just after the failure, instead of any other task.
Perhaps I misunderstood this part.
> ansible-playbook -i ./environments/CD-5525/hosts.yml main_CD-5525.yml -bK
BECOME password:
PLAY [Start MySql cluster databases] ***********************************************************************************************
TASK [CD-5525 : debug] *************************************************************************************************************
ok: [xxx] => {
"msg": "I execute normally"
}
ok: [yyy] => {
"msg": "I execute normally"
}
ok: [zzz] => {
"msg": "I execute normally"
}
TASK [CD-5525 : i force a failure] *************************************************************************************************
skipping: [yyy]
skipping: [zzz]
fatal: [xxx]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": ["/bin/false"], "delta": "0:00:00.002018", "end": "2022-04-18 06:41:39.602367", "msg": "non-zero return code", "rc": 1, "start": "2022-04-18 06:41:39.600349", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
TASK [CD-5525 : debug] *************************************************************************************************************
ok: [yyy] => {
"msg": "I never execute, due to the above task failing, :-("
}
ok: [zzz] => {
"msg": "I never execute, due to the above task failing, :-("
}
TASK [CD-5525 : debug] *************************************************************************************************************
ok: [xxx] => {
"msg": "I caught an error"
}
TASK [CD-5525 : i force a failure in middle of recovery! >:-)] *********************************************************************
fatal: [xxx]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": true, "cmd": ["/bin/false"], "delta": "0:00:00.002136", "end": "2022-04-18 06:41:43.100661", "msg": "non-zero return code", "rc": 1, "start": "2022-04-18 06:41:43.098525", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
PLAY RECAP *************************************************************************************************************************
xxx : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=1 ignored=0
zzz : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
yyy : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
In my example, if the first task (Starts the fist node ...) fails, should it continue with the second task (Start the rest of nodes) instead of going to the rescue block ?
block:
- name: Starts the first node of the cluster in bootstrap mode
shell: /etc/init.d/mysql bootstrap-pxc
when: inventory_hostname == groups.CD5525[0]
become: yes
register: return_out
- name: Start the rest of nodes
systemd:
state: started
name: mysql
when: inventory_hostname != groups.CD5525[0]
become: yes
register: screen_out
Thank you
Javier