My case is:
If group doesn't exist in inventory file then I want to throw an error instead of getting a warning like: 'No host matched'.
Ansible version: 2.4
Add a play checking for group existence to the top of your playbook. Use groups
magic variable in the condition:
---
- hosts: localhost
gather_facts: no
connection: local
tasks:
- fail:
when: "'my_group' not in groups"