Matt,

you sir are a life saver! That is exactly what I am looking for.

Thanks much!!

On Tuesday, November 5, 2019 at 2:22:05 PM UTC-6, Matt Martz wrote:
>
> By doing this:
>
> {{ [more_servers] }}
>
> You are creating a python list, and then printing it.
>
> I think you instead want:
>
> [{{ more_servers }}]
>
> On Tue, Nov 5, 2019 at 2:11 PM Tom Davison <tntda...@gmail.com 
> <javascript:>> wrote:
>
>> Hi everyone.
>>
>> When trying to template out a weblogic wl.properties file, I am running 
>> into a Jinja2 template problem.
>>
>> Here is a snippet of code I am running into issues with:
>>
>>
>> ################################################################################
>> # ADDITIONAL MACHINE PROPERTIES
>>
>> ################################################################################
>> ADDITIONAL_MACHINES={% for server in my_servers %}{{ server }}{% if not 
>> loop.last %},{% endif %}{% endfor %}
>>
>> {% for more_servers in my_servers %}
>> {{ [more_servers] }}LISTEN_ADDRESS={{ ansible_nodename }}
>> {% endfor %}
>>
>> BAD OUTPUT:
>>
>> ################################################################################
>> # ADDITIONAL MACHINE PROPERTIES
>>
>> ################################################################################
>>
>> ADDITIONAL_MACHINES=myserver02,myserver03,myserver04,myserver05,myserver06,myserver07,myserver08
>> [u'myserver02']LISTEN_ADDRESS=ansible_host
>> [u'myserver03']LISTEN_ADDRESS=ansible_host
>> [u'myserver04']LISTEN_ADDRESS=ansible_host
>> [u'myserver05']LISTEN_ADDRESS=ansible_host
>> [u'myserver06']LISTEN_ADDRESS=ansible_host
>> [u'myserver07']LISTEN_ADDRESS=ansible_host
>> [u'myserver08']LISTEN_ADDRESS=ansible_host
>>
>>
>> It appears that the square brackets around the j2 variable more_servers 
>> cause rendering issues and makes python inject the unicode "u" as well as 
>> single quotes into the final output. 
>>
>> EXPECTED OUTPUT:
>>
>> ################################################################################
>> # ADDITIONAL MACHINE PROPERTIES
>>
>> ################################################################################
>>
>> ADDITIONAL_MACHINES=myserver02,myserver03,myserver04,myserver05,myserver06,myserver07,myserver08
>> [myserver02]LISTEN_ADDRESS=ansible_host
>> [myserver03]LISTEN_ADDRESS=ansible_host
>> [myserver04]LISTEN_ADDRESS=ansible_host
>> ['myserver05]LISTEN_ADDRESS=ansible_host
>> [myserver06]LISTEN_ADDRESS=ansible_host
>> [myserver07]LISTEN_ADDRESS=ansible_host
>> [myserver08]LISTEN_ADDRESS=ansible_host
>>
>>
>> I have tried many different filters to get this to work, but just cannot 
>> get it. Filters include: to_json, to_nice_json, to_yaml, to_nice_yaml,join, 
>> replace.
>>
>> Any help would be greatly appreciated! 
>>
>>  - Tom
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ansible Development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to ansibl...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-devel/c0eb5d63-a2a4-4276-90f6-93db66c74cdd%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-devel/c0eb5d63-a2a4-4276-90f6-93db66c74cdd%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-devel/8b326ea5-e9d8-4d3d-9431-3af3f82fb94f%40googlegroups.com.

Reply via email to