Ansible + jinja2 macro

46 views
Skip to first unread message

ProfHase

unread,
Oct 31, 2018, 6:39:22 AM10/31/18
to Ansible Project
Hi @all,

I am trying to use a macro in an ansible template:

{% macro logging(ltype) %}
{% if ltype == 'fluentd' %}
logging
:
  driver
: 'fluentd'
  options
:
    tag
: "{{ app_name }}.{{ '{{' }}.Name{{ '}}' }}"
    labels
: "mylabel"
{% endif %}
{% endmacro %}

...                                                                                                                  
   
{{ logging('fluentd') }}                                                                                          
...

When I render it (template module), I am always getting

...
   logging
:
  driver
: 'fluentd'
  options
:
    tag
: "test.{{.Name}}"
    labels
: "fhg.iam.appname,fhg.iam.hostname,fhg.iam.publicip,fhg.iam.privateip"

...

So apparently 'logging is indented right, but everything else just loses its indentation. Has anyone else got any similar problem?

Tony Chia

unread,
Nov 1, 2018, 1:16:03 PM11/1/18
to Ansible Project
Have you tried this to see if it removes the extra ident?
...                                                                                                                   
{{ logging('fluentd') }}                                                                                          
...

ProfHase

unread,
Nov 6, 2018, 7:29:50 AM11/6/18
to Ansible Project
yes, thanks, funnily there is some logics behind that. The macro is like you would paste it at the spot. so, the first line is indented, and the others are not...

于宗洋

unread,
Nov 6, 2018, 7:37:50 AM11/6/18
to ansible...@googlegroups.com, Ansible Project

I don't think so, at least in the examples I've seen so far, you can change user information in tables at will, but in fact you won't be allowed to do so in version 3.6 + of mongo.



--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c715437c-dfb1-4fd9-a34c-52202f36b8c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages