How access dictionary in a jinja2 template?

I am trying to come up with a play book to install cassandra. Here each node has a calculated token (not a random hash) and is unique. So, I have defined a dictionary in the vars/cassandra_variables.yml as below. The IPs 192.168.56.x happen to be the ansible_inventory hosts which are defined in the inventory file as [cassandrahosts]

How would I access the dictionary through jinja2 template.?

vars/cassandra_variables.yml

tokens:

192.168.56.1: 0
192.168.56.2: 56713727820156410577229101238628035242
192.168.56.3: 113427455640312821154458202477256070485

192.168.56.x hosts are coming in from inventory file and in the “cassandra.j2” I have the following

initial_token: {{ tokens[‘{{ inventory_hostname}}’] }}

tokens[“{{ inventory_hostname}}”] is evaluated but not {{ tokens[‘{{ inventory_hostname}}’] }}

How do I get it to work? Where am I going wrong? Any help is much appreciated.

-SR

Perhaps I’m not understanding what you’re after, but this worked for me:
initial_token: {{ tokens[inventory_hostname] }}

Works for me now. I over worked on this and ignored the basics. Thanks Guy Matz.