Thank God, no Python evals.

You can access hostvars programatically like this:

hostvars[hostname][factname]

So you can build the factname string programatically and get to them that
way.




On Wed, Nov 27, 2013 at 5:16 AM, Brian Little <[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)
>
> #print the mac addresses and driver (or similar)
> {% for interface in ansible_interfaces %}
>
> {{ interface }}
> mac= {{ eval('ansible_' + interface).macaddress }}
> driver = {{ eval('ansible_' + interface).module }}
>
> {% endfor %}
>
>
> Where the host variables are like this ( an example ):
>
> "ansible_interfaces": [
>   "eth1",
>   "eth2"
> ],
> "ansible_eth1": {
>   "active": false",
>   "device": "eth1",
>   "macaddress": "00:00:00:FF:FF:FF",
>   "module": "igb",
>   "mtu": 1500,
>   "type": "ether"
> },
> "ansible_eth2": {
>   "active": false",
>   "device": "eth2",
>   "macaddress": "AA:00:00:FF:FF:AA",
>   "module": "ixgbe",
>   "mtu": 9000,
>   "type": "ether"
> },
>
> Is something like this possible, or do I have to some combination of
> templating using with_items, and then using assemble to stick it together?
>
> --
> 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.

Reply via email to