Would you mind sharing the full body of the task that pertains to this as 
well as the template file?

On Tuesday, March 10, 2015 at 12:19:46 PM UTC-4, John McNulty wrote:
>
>
> So the reason why I tried using union was this github issue ( 
> https://github.com/ansible/ansible/issues/7495 ) which implied it should 
> work (assuming the PR got actioned).
>
> But looking at the code ( lib/ansible/runner/filter_plugins/mathstuff.py ) it 
> doesn't look like that's the case as union() doesn't match what this 
> article (
> http://stackoverflow.com/questions/38987/how-can-i-merge-two-python-dictionaries-in-a-single-expression)
>  
> describes as the 'pythonic way'.
>
> z = x.copy()
> z.update(y)
>
> So I tried to emulate that with ...
>
> with_dict: "{% set r = host_routes.copy() %}{% r.update(standard_routes) 
> %}{{ r }}"
>
> resulting in ..
>
> fatal: [localhost] => template error while templating string: unknown tag 
> 'r'
>
> I've also scanned all the Jinja2 filters ( 
> http://jinja.pocoo.org/docs/dev/templates ) looking for a potential 
> candidate and can't see anything that looks suitable.  
>
> I really am an Ansible & jinja2 pseudo-novice, so I'm kind of stumbling 
> around a bit here :)
>
>
>
> On Tuesday, 10 March 2015 13:23:49 UTC, John McNulty wrote:
>>
>>
>> Hi,
>>
>> So here's the scenario - I'm given a data structure that when converted 
>> to yaml looks like this (names & numbers invented).
>>
>> host_routes:
>>   route-oob:
>>     device: bond.123
>>     routes:
>>       10.118.0.0/16: '10.118.255.254'
>>   route-int:
>>     device: bond.456
>>     routes:
>>       172.168.0.0/23: '172.168.1.254'
>>
>> I can use that with a template to create the network-script route files 
>> needed, that's easy enough.   But in real life there can be up to several 
>> OOB routes that this host will need depending on which datacentre / hall / 
>> security zone it resides in. e.g. 
>>
>> standard_routes:
>>   route-oob:
>>     device: bond.123
>>     routes:
>>       10.198.0.0/24: '10.118.255.254'
>>
>> I'd like to add these additional routes to the appropriate group_var file 
>> and then merge them together when creating the route files.   I can't get 
>> this to work though.  I've tried all the following:
>>
>> with_dict: host_routes|union(standard_routes)
>>
>> with_dict: union(host_routes, standard_routes)
>>
>> with_dict: host_routes + standard_routes
>>
>>
>> and get the same error every time ..
>>
>> fatal: [localhost] => with_dict expects a dict
>>
>>
>> Is there another filter or some other way of doing this?   I don't want 
>> to change the default hash_behaviour to merge just for this one use case as 
>> that has much wider implications.
>>
>> Thanks,  John
>>
>>
>>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/ed2489e4-1d13-4471-b5c9-d4cf79d5ef88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to