How to signal an error from a Jinja expression?

I have the following task in a role:

command: >-
passwd -
{%- if ansible_system == ‘SunOS’ %}N
{%- elif ansible_system == ‘Linux’ %}l
{%- else %}
{{ “Unknown OS”/0 }}
{%- endif -%}

How to throw an error for the unknown ansible_system from within the role?

You cannot, but you can do this:

- command: ....
  when: ansible_system is defined

- fail: msg=' you did not define ansible_system!"
  when: not ansible_system is defined