Random aside: using that CSV lookup plugin will be pretty inefficient --
particularly in larger setups. It will load the local file for every host
in the host loop, and then once for every name in the names list.
A better way to do this would be to save the mapping as a YAML dictionary
and use the stock systems in Ansible here. However, that's not always
possible.
The idea of a way to cache lookup plugin results was explored previously
though technically requires some IPC so we maintain the cache in one
process *OR* we extend fact caching proposed for 1.5 to also cache lookup
plugin results when evaluated, with, say, lookup_cached, versus lookup, and
specify a timeout.
lookup_cached('plugin_name', 'param string', timeout_in_seconds)
Hmmm.... ideas.... :)
On Thu, Nov 28, 2013 at 3:20 AM, Jan-Piet Mens <[email protected]> wrote:
> > Is there anything in jinja templating to "eval" a variable name? Where I
> > can add a string to a variable, and reference another variable
> > I'm interesting in doing something like this (example pseudocode)
>
> I did this recently for testing a lookup plugin; I think it's along the
> lines of what you want:
>
> {% for name in names -%}
>
> {# Build param consisting of key and file= #}
> {%
> set param = ' '.join(( name, "file=input.csv",
> "default=OhNo!", "delimiter=;"))
> -%}
> {% set val = lookup('csvfile', param) -%}
> {{ name }} is in fact "{{ val }}"
> {% endfor %}
>
> using the variables you want, of course. :)
>
> -JP
>
> --
> 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].
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
Michael DeHaan <[email protected]>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/
--
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].
For more options, visit https://groups.google.com/groups/opt_out.