Thank you for the reply.  That gets me to the same workaround I had before 
though.  The problem is that it still shows that the playbook failed 
overall as the host is shown in red at the end because the unreachable 
error does not trigger the rescue block, and it still gets shown at the end 
as the playbook failing overall even though the logic is in there to 
recover from the errors and be successful.  I think that due to the way 
Ansible handles unreachable errors with blocks, there won't be a way to 
properly handle it to avoid the playbook showing as failed at the end.  
While it's not an issue right now for testing and dev stuff, people are 
going to be concerned if this behavior occurs in production.  
Unfortunately, all the ignore_unreachable keyword does is prevent the 
playbook from stopping on the unreachable error.

This is the scrubbed playbook for reference:

tasks:
- name: Test WinRM connectivity
block:
- name: Test WinRM connectivity
win_ping:
ignore_unreachable: true
register: ping

- name: this forces a recoverable fail
assert:
that:
- not ping['unreachable']|default(False)
# depending on connection plugin, you can inspect ping['msg'] for the 
specific auth errors you can rescue

rescue:
- name: Change admin account name
set_fact:
ansible_user: '[new user]'

- name: Test WinRM connectivity again
win_ping:

[image: ansible_unreachable_fail.PNG]

On Thursday, November 4, 2021 at 4:26:28 PM UTC-4 bc...@redhat.com wrote:

> You can do this now w/o waiting for a new feature. 
>
> - block: 
> - win_ping: 
> ignore_unreachable: true 
> register: ping 
>
> - name: this forces a recoverable fail 
> assert: 
> that: 
> - not ping['unreachable']|default(False) 
> - # depending on connection plugin, you can inspect ping['msg'] 
> for the specific auth errors you can rescule 
>
> rescue: 
> - action: do stuff here 
>
>
>
> -- 
> ---------- 
> Brian Coca 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/2cccb935-07a4-44cb-b18e-8021cea576b2n%40googlegroups.com.

Reply via email to