Multiple host variables with same key in Ansible inventory files

I have multiple meta_addons variable associated with a host, like:

host_name meta_addons=grafana meta_addons=elasticsearch meta_addons=prometheus

When I access them in my jinja2 template, it reads only the last one- prometheus. Is there a way of iterating over all of them one by one?

no, last one will overrite previous ones make it a list,

host_vars/host_name.yml
meta_addons:
  - grafana
  - elasticsearch
  - prometheus

That's because it will overwrite the variable so only the last one will stick.

You need to make it a list and loop over it with with_items.

host_name meta_addons=['grafana','elasticsearch','prometheus']

This won't work so go for Brian's solution.