I have a playbook with multiple plays, where each play is executed on a 
different group of hosts. The behavior that I'm looking for is that if any 
host in any group is unreachable, the whole playbook fails immediately. 

Below is a small repro of the behavior I'm seeing. Using any_errors_fatal, 
I'm able to prevent any steps in the first play from running if any of the 
hosts in the group are inaccessible. However, since all of the hosts in the 
second play are accessible, that play still runs.

Is there a way that I can get the playbook run to fail out as soon as the 
first play fails?

executing with 

ansible-playbook playbook-test-unreachable-fatal.yml -i inventory

inventory:
[just_good_host]
localhost ansible_connection=local 

[good_and_bad_hosts]
localhost ansible_connection=local
not.a.real.host.com


playbook-test-unreachable-fatal.yml:
---
- name: Try to write a timestamp to a file on all hosts
  gather_facts: true
  hosts: good_and_bad_hosts
  any_errors_fatal: true
  tasks:
    - name: >
        Add a timestamp to a file, when run with any_errors_fatal=true,
        this will never get run on any host, as I expect
      lineinfile:
        create: yes
        dest: "{{ ansible_env.HOME}}/test_file_1.txt"
        state: present
        line: "{{ ansible_date_time.iso8601 }}"

- name: Try to write a timestamp to a file on just the good host
  gather_facts: true
  hosts: just_good_host
  any_errors_fatal: true
  tasks:
    - name: >
        Add a timestamp to a second file, this succeeds on the accessible 
host,
        despite a fatal error having occurred in a previous play in this
        playbook
      lineinfile:
        create: yes
        dest: "{{ ansible_env.HOME}}/test_file_2.txt"
        state: present
        line: "{{ ansible_date_time.iso8601 }}"



-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Attachment: inventory
Description: Binary data

Attachment: playbook-test-unreachable-fatal.yml
Description: Binary data

Reply via email to