fail a play if a hosts: value is incorrect?

Is it possible to configure Ansible to fail early if a hosts: value is incorrect, i.e. doesn’t match a target machine in the inventory?

If the hosts: value is undefined like this:

`

  • name: Test module(s)
    hosts:
    `

Then Ansible throws this: “ERROR! the field ‘hosts’ is required but was not set”

I am wondering if similar behaviour can be configured if the hosts: value is misconfigured.

It will skip the play cause no groups/hosts match.