SuMa 3.2.3: Jinja2 templates with control structures

Hi *,

anyone had success with Jinja2 profile templates in SuMA 3.2.3, using control structures?

I had created a Profile via SuMa web UI, with an autoyast installation profile, containing Cheetah variables. For tests, I converted this to Jinja2:

#template=jinja2
<?xml version="1.0"?>
<!DOCTYPE profile>
...
<hostname>{{ hostname }}</hostname>
...

Works like a charm. But once I try to add Jinja2 control structures, in fact anything with “{% %}”, cobbler bails out. Unless I turn up the log level for cobblerd, nothing is reported in cobblerd.log and “cobbler system getks --name mysystemname” reorts

suma:/tmp # cobbler system getks --name mysystemname
 # This kickstart had errors that prevented it from being rendered correctly.
# The cobbler.log should have information relating to this failure.
suma:/tmp # 

With log level set to INFO (actually DEBUG, but the messages are at INFO level), I see at least a hint in cobblerd.log:

Fri Nov 16 14:06:03 2018 - INFO | REMOTE generate_kickstart; user(?)
Fri Nov 16 14:06:03 2018 - INFO | generate_kickstart
Fri Nov 16 14:06:03 2018 - INFO | autoyast XML file found. Checkpoint: profile=<cobbler.item_profile.Profile instance at 0x7fe4c4d87908> system=<cobbler.item_system.System instance at 0x7fe4c738c290>
Fri Nov 16 14:06:03 2018 - INFO | Exception occured: <class 'xml.parsers.expat.ExpatError'>
Fri Nov 16 14:06:03 2018 - INFO | Exception value: not well-formed (invalid token): line 1, column 1
Fri Nov 16 14:06:03 2018 - INFO | Exception Info:
  File "/usr/lib/python2.7/site-packages/cobbler/remote.py", line 1061, in generate_kickstart
    return self.api.generate_kickstart(profile,system)
   File "/usr/lib/python2.7/site-packages/cobbler/api.py", line 694, in generate_kickstart
    return self.kickgen.generate_kickstart_for_system(system)
   File "/usr/lib/python2.7/site-packages/cobbler/kickgen.py", line 254, in generate_kickstart_for_system
    return self.generate_kickstart(profile=p, system=s)
   File "/usr/lib/python2.7/site-packages/cobbler/kickgen.py", line 294, in generate_kickstart
    data = self.generate_autoyast(profile,system,data)
   File "/usr/lib/python2.7/site-packages/cobbler/kickgen.py", line 110, in generate_autoyast
    document = xml.dom.minidom.parseString(raw_data)
   File "/usr/lib64/python2.7/xml/dom/minidom.py", line 1928, in parseString
    return expatbuilder.parseString(string)
   File "/usr/lib64/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
    return builder.parseString(string)
   File "/usr/lib64/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)

Well, it might have been easy to mess up XML, but this happens even with

#template=jinja2
<?xml version="1.0"?>
<!--
{% i = "something" %}
{{ i }}
-->
<!DOCTYPE profile>
...

Is this some error on my behalf? Or is it a problem with the parser, prepared for “{{ }}”, but not for “{% %}” (hence the “invalid token” error )?

Regards,
J

Issues solved:

[QUOTE=jmozdzen;55293]

#template=jinja2
<?xml version="1.0"?>
<!--
{% i = "something" %}
{{ i }}
-->
<!DOCTYPE profile>
...

Is this some error on my behalf?[/QUOTE]

it indeed is. Make it a valid Jinja2 syntax and all is well:

#template=jinja2
<?xml version="1.0"?>
<!--
{% [U][B]set[/B][/U] i = "something" %}
{{ i }}
-->
<!DOCTYPE profile>
...

Too many languages with too subtle differences :frowning:

Regards,
J