Playbook gives inconsistent results

I’ve got a multi-task playbook - if I run it against Servers A & B, all tasks run for both servers. If I run it against just B it fails at the first task and stops.

My view is if you run a playbook against a server you should get consistent results.

I raised this as a Bug in GitHub but it was closed as “That’s the way it is”. No disrespect to the Dev who closed that but I want to get other opinions on this.

MKPhil

There's no way to figure out what's happening from just that description,
did you provide a test case on github?

Can you share a link to the issue that was closed or at least share the playbook so we can have a chance understanding what is going on.

Here’s a basic Playbook which has this functionality. All tasks run for servers A and B but fails when run only against B where B is a server that cannot be contacted. My point is that if I run this against Server B I should get the same result regardless of what other servers I run it against.

`

---
- name: Check Servers
  gather_facts: false
  hosts: windows
  tasks:
    - name: Check server with win_ping
      win_ping:
      register: result
      ignore_errors: yes
    - meta: clear_host_errors
    - debug:
        msg: "{{ inventory_hostname | quote }} {{ result | default() }}"
...

`

As I mentioned in the ticket, this is not inconsistent, this is just
how the rules for fatal and non fatal errors work. Since running only
B gets a fatal error (no hosts left in play to continue) the play ends
before the `meta` task, when any other host is left (like when you add
A to the mix) the error is non-fatal and the `meta` task gets
executed.

if you just want consistency, this will make your play behave the same
in both cases:

- name: Check Servers
  gather_facts: false
  hosts: windows
  any_errors_fatal: True
  tasks:
    - name: Check server with win_ping
      win_ping:
      register: result
      ignore_errors: yes
    - meta: clear_host_errors
    - debug:
        msg: "{{ inventory_hostname | quote }} {{ result | default() }}"

But that is not very useful, if you actually want to get the debug
messages in all cases I recommend the following:

- name: Check Servers
  gather_facts: false
  hosts: windows
  tasks:
    - block:
      - name: Check server with win_ping
        win_ping:
        register: result
     always:
      - debug:
          msg: "{{ inventory_hostname | quote }} {{ result | default() }}"