I am trying the following playbook. But even after getting the error from handler, the rescue section is not working.
handlers:
- name: port status
shell: netstat -nltp | grep {{ app1_port }}
register: port
listen: port_status
- name: display port status
debug: var=port.stdout_lines
listen: port_status
tasks:
- name: Reload service if checks fail
block:
- name: Check process status
shell: ps -aux | grep {{ app1 }} | grep -v grep
notify: port status
rescue:
- name: fetching proc ids
shell: ps -aux | grep {{ app2 }} | grep -v grep | awk '{print $2}'
register: result
ignore_errors: True
- name: Reloading config
shell: "kill -HUP {{ item }}"
with_items:
- "{{ result.stdout_lines }}"
notify: port_status
Bellow is the output I'm getting while running.
TASK [Check service status] ********************************************************************************************************* changed: [localhost]
RUNNING HANDLER [port status] **************************************************************************************************************** fatal: [localhost]: FAILED! => {"changed": true, "cmd": "netstat -nltp | grep 3306", "delta": "0:00:00.017951", "end": "2019-03-13 22:04:41.024950", "msg": "non-zero return code", "rc": 1, "start": "2019-03-13 22:04:41.006999", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
NO MORE HOSTS LEFT ***************************************************************************************************************** to retry, use: --limit @/home/sachin/ansible.retry
PLAY RECAP ***************************************************************************************************************** localhost : ok=1 changed=1 unreachable=0 failed=1