Hello,
Replying to an old thread but this is relevant to what I am trying to do.
I have defined the tokens as a dictionary in the vars_file as below.
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.yaml I have the following
initial_token: {{ tokens['{{ inventory_hostname}}'] }}
tokens["{{ inventory_hostname}}"] is evaluated but not {{ tokens['{{
inventory_hostname}}'] }}
How do I get it done with jinja2? Where am I going wrong? Any help is much
appreciated.
-SR
On Wednesday, March 6, 2013 5:40:14 PM UTC-6, Peter Sankauskas wrote:
>
> Hi,
>
> I am creating a playbook that creates a valid cassandra.yaml file for each
> node in a new cluster using a jinja2 template. What this file needs is a
> different token for each node, but I do not know how to do this with
> Ansible.
>
> So the part of the template in question looks like this:
>
> initial_token: {{ token }}
>
>
> In this example, I have 6 nodes. I can generate the tokens for each using
> this script:
>
> $ ./tokenbuilder.py 6
> {
> "0": {
> "0": 0,
> "1": 28356863910078205288614550619314017621,
> "2": 56713727820156410577229101238628035242,
> "3": 85070591730234615865843651857942052864,
> "4": 113427455640312821154458202477256070485,
> "5": 141784319550391026443072753096570088106
> }
> }
>
>
> I believe there is a way to get the output of that script into a variable
> in Ansible so that I can access it by {{ tokens[0] }}. (Any tips
> appreciated).
>
> In any case, I can use a playbook that has
>
> vars:
> tokens:
> 0: 0
> 1: 28356863910078205288614550619314017621
> 2: 56713727820156410577229101238628035242
>
> ...
>
>
>
> tasks:
> - name: Copy over the templated cassandra.yaml config file
> template: src=templates/cassandra.yaml.j2
> dest=/etc/cassandra/cassandra.yaml
>
>
> to do the same thing.
>
> The question is, how can I then get each of the 6 hosts to use one of
> these array values in the template? So that when the template is evaluated:
>
> host1 has token = tokens[0] = 0
> host2 has token = tokens[1] = 28356863910078205288614550619314017621
> host3 has token = tokens[2] = 56713727820156410577229101238628035242
> host4 has token = tokens[3] = 85070591730234615865843651857942052864
> host5 has token = tokens[4] = 113427455640312821154458202477256070485
> host6 has token = tokens[5] = 141784319550391026443072753096570088106
>
>
>
> All hosts are part of the same group in the inventory. Is there a trick to
> get the index of a host in a group?
>
> I would really appreciate anyone pointing me in the right direction.
>
> Thanks,
> Peter
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/92ad02b2-bf0a-487d-8e6b-edce86e7c2fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.