There are many cases where running a playbook across all hosts would be disastrous. Instead the playbook is used by limiting the hosts using the --limit argument.
It would be ideal if we could force the user to use the --limit argument, and fail the Ansible run if the --limit argument is missing.
We can do that with the following task code.
tasks:
- name: "Fail if no --limit set"
fail:
msg: "you must use -l or --limit"
when: ansible_limit is not defined
run_once: true