Playbook fails if nothing matches?

Dumb n00b question. I am trying to run several play books against one system. If any one of the play books fails, Ansible exits with an RC = 1. I think I have it distilled this down to the below code:

[root@pdxvnxutil ansible]# ansible-playbook -l farmer playbooks/test.yml
SSH password:

PLAY: ***************************************************************************

TASK [setup] ********************************************************************
ok: [farmer]

PLAY RECAP **********************************************************************
farmer : ok=1 changed=0 unreachable=0 failed=0

[root@pdxvnxutil ansible]# echo $?
0
[root@pdxvnxutil ansible]# cat playbooks/test.yml

  • hosts: farmer
    [root@pdxvnxutil ansible]#

As farmer does not match fuzzy_not_farmer, I would expect the below to fail the first hosts test, but not fail totally out! The play book exits and never gets to the rest of the play book?
[root@pdxvnxutil ansible]# ansible-playbook -l farmer playbooks/test.yml
SSH password:

PLAY: ***************************************************************************
skipping: no hosts matched

PLAY RECAP **********************************************************************

[root@pdxvnxutil ansible]# echo $?
1

[root@pdxvnxutil ansible]# cat playbooks/test.yml

  • hosts: fuzzy_not_farmer (Exits with 1, and never gets to the next host)

  • hosts: farmer

[root@pdxvnxutil ansible]#

Any ideas?

Bug in Ansible 2.0.0 dev branch.

this is by design, if all hosts fail in a play or no hosts are
matched, ansible ends the execution.

v1 doesnt stop execution if no hosts were matched in the play.

So, version 1 works great.

I was more worried about v2 failing with rc 1.

If this is a known “feature”, how do I define multiple sets of hosts in one play book; assuming the first set of hosts don’t match the rule and fails?

We'll check the behavior and get back to you.

Confirmed, this is a bug, a play that doesn't match any hosts to begin
with should be skipped but subsequent plays should run.

But a play that runs out of hosts due to errors, does interrupt the
whole playbook run.

Thanks!

Just fixed on the devel branch (4b28a51f25226a1c6a86892b774a8bcea5a63883).

Thanks!

A few days ago while my colleague was writing a deploy playbook, he encountered a problem where he wanted the whole playbook to fail if any hos in a play failed, but it didn’t work like that. If at least one host in a play didn’t fail, Ansible continued with the next play. It only stopped if all hosts in a play failed.

Then we tried his playbook with 2.0 and it didn’t work the same. With 2.0 if one host in a play failed, Ansible would stop execution. Is this intentionally, or is it also a bug?

I really hope it is intentionally, since it’s really annoying if you need every host in a play to succeed, to make workaround checks to see if any of the hosts failed.