This seems to be a very un-ansible-like bad idea and you shouldn't do it.

In general, Ansible is not meant to be a programming language, and
inventory is meant to be something edited by humans or pulled from a source
of authority -- I'm probably not understanding why you want to do this
though.

Let's step back here -- what's the use case for needing to do something
like this?

Give us more info about the real world thing you are trying to model, and
we can likely share some more Ansible-like suggestions.

--Michael


On Tue, Apr 29, 2014 at 10:30 PM, Kristopher Cieplak <[email protected]>wrote:

> I am wondering if this is possible I have a group_vars file with some
> variables in it, and I need to set, the list is generated from the
> inventory and a mapping to the ec2 private ip address.
>
> For example in my group_vars file:
> cassandra: {keyspace: default, log_time: false, hosts: [ "{% for host in
> groups['tag_role_cassandra_true']
> %}{{hostvars[host].ec2_private_ip_address}}{% if not loop.last %},{% endif
> %}{% endfor %}" ]}
>
> This ends up being the following if I dump it using the "debug" directive:
> "msg": "cassandra {'keyspace': 'default', 'log_time': False, 'hosts':
> [u'172.31.2.85,172.31.2.84,172.31.2.86,172.31.2.83']}"
>
> As you can see that is a list of one string. I want a list of all hosts,
> in this case four hosts, i.e it should be:
> 'hosts': ['172.31.2.85', '172.31.2.84' ,'172.31.2.86', '172.31.2.83']
>
> Does anyone know anyway to loop over all the hosts do the conversion to
> private ip and append to the "list".
>
> My fallback is to generate it as a string, then use that lower down , but
> would be nice to have the list, as I can output it in various templates
> differently.
>
> Thanks
>
> --
> 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/572e3dba-2fc4-4f6b-8a7a-de506a1f02c6%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/572e3dba-2fc4-4f6b-8a7a-de506a1f02c6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CA%2BnsWgzfypHrhWxU%3DuyE%3DMwCYjF3POd_0GmrrxiajEmK0a3URw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to