ansible-playbook exits if all hosts in a play fails

This is very close to ansible-playbook exits if host list empty, even if later plays could still run

I have a large playbook that has multiple plays. I would like the playbook to execute all plays to the end of the playbook, even if all hosts in a particular play fail or are unreachable. I cannot find the right set of variables to make this happen.

Playbook looks something like this:

- name: play1
  hosts:
    - host1
    - host2
  tasks:
    - task1-1
    - task1-2

- name: play2
  hosts:
    - host2
    - host3
  tasks:
    - task2-1
    - task2-2

- name: play3
  hosts:
    - host4
    - host5
  tasks:
    - task3-1
    - task3-2

If host1 and host2 are unreachable or fail, I would still like the playbook to continue and execute play2 and play3. Note that the hosts in play3 are distinct from the ones in play1 and play2.

I’ve tried putting each play in a block with a rescue that uses the meta task “clear_host_errors” and that seems to get some, but not all executions.

I’ve tried setting “ignore_unreachable: true” and that kind of works, but executes tasks on unreachable hosts, which then error for missing ansible facts. I need to have the playbook exit with unreachable for those hosts, not in an error state for those hosts.

This is by design, in almost all cases you don’t want to continue a run when everything is failing or unreachable.

If your plays are independent of previous play failures I would separate them into different playbooks and run them in their own process and not on the same run.