0

I've written the following playbook. I expect an error from the second play, but the first and third to run. What I get is the first running, the second failing, and the third is completely ignored.

If I make the second play succeed then the third play works.

How can I get the third play to execute even when the second play fails?

- name: First local task
  hosts: localhost
  tasks:
  - add_host:
      name: dummy.example.com
      groups: test

- name: Failing remote host
  hosts: test
  tasks:
    - debug:
        msg: 'test'

- name: "This one should run too?"
  hosts: localhost
  tasks:
    - debug:
        msg: 'success!'
sherbang
  • 361
  • 3
  • 6

1 Answers1

1

You didn't specify the exact error in your question. However generally you can add ignore_errors: yes to your second task to proceed with the third task, even if errors occur. If the error, is that your host "test" isn't reachable than you have to use ignore_unreachable: yes like below:

- name: First local task
  hosts: localhost
  tasks:
  - add_host:
      name: dummy.example.com
      groups: test

- name: Failing remote host
  hosts: test
  tasks:
    - debug:
        msg: 'test'
  ignore_unreachable: yes

- name: "This one should run too?"
  hosts: localhost
  tasks:
    - debug:
        msg: 'success!'
Lorem ipsum
  • 892
  • 5
  • 15
  • I wouldn't expect to need to ignore errors. localhost never had an error so shouldn't it keep executing plays even if all the remote hosts fail (unreachable or any other kind of error)? – sherbang Sep 25 '20 at 18:20
  • 1
    @sherbang Why would you expect this? I found this link, were they discuss this behavior: https://github.com/ansible/ansible/issues/39527. Last comment in this discussion will answer your question i hope. – Lorem ipsum Sep 25 '20 at 18:28
  • Thanks for that link. I expected it to continue as long as there were any valid hosts. Since only the test host failed, but not localhost I expected the playbook to continue. Apparently I was wrong. – sherbang Sep 25 '20 at 18:56