ERROR: Undefined when ifup -a Is Executed; ERROR: Failed to Render Template when inquiry Is Executed



ifupdown2 supports Mako templates. When the python-mako package is installed and Mako code is incorrectly commented in /etc/network/interfaces, the following error may appear when ifup -a is executed.

$sudo ifup -a

$sudo ifup -a -d
DEBUG: args = Namespace(CLASS=None, all=True, debug=True, excludepats=None, force=False, iflist=[], jobs=-1, noact=False, noaddons=False, nocache=False, perfmode=False, printdependency=None, quiet=False, verbose=False, withdepends=False)
DEBUG: creating ifupdown object ..
INFO: loading builtin modules from /usr/share/ifupdownaddons
DEBUG: reading interfaces file /etc/network/interfaces
Traceback (most recent call last):
  File "/sbin/ifup", line 358, in <module>
  File "/sbin/ifup", line 328, in main
  File "/sbin/ifup", line 43, in run_up
  File "/usr/lib/python2.7/dist-packages/ifupdown/", line 669, in up
  File "/usr/lib/python2.7/dist-packages/ifupdown/", line 423, in read_iface_config
    return self.read_default_iface_config()
  File "/usr/lib/python2.7/dist-packages/ifupdown/", line 420, in read_default_iface_config
  File "/usr/lib/python2.7/dist-packages/ifupdown/", line 264, in load
    return self.read_file(filename)
  File "/usr/lib/python2.7/dist-packages/ifupdown/", line 260, in read_file
    filedata = self.run_template_engine(filedata)
  File "/usr/lib/python2.7/dist-packages/ifupdown/", line 244, in run_template_engine
    return t.render()
  File "/usr/lib/python2.7/dist-packages/mako/", line 397, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/lib/python2.7/dist-packages/mako/", line 764, in _render
    **_kwargs_for_callable(callable_, data))
  File "/usr/lib/python2.7/dist-packages/mako/", line 796, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/usr/lib/python2.7/dist-packages/mako/", line 822, in _exec_template
    callable_(context, *args, **kwargs)
  File "memory:0x482640d0", line 23, in render_body
  File "/usr/lib/python2.7/dist-packages/mako/", line 194, in __str__
    raise NameError("Undefined")
NameError: Undefined

Alternately, you may see the following error when running ifquery on an interface:

cumulus@switch:~$ ifquery swp1
error: /etc/network/interfaces: failed to render template (Undefined). Continue without template rendering ...
auto swp1
iface swp1 inet static
down ip addr flush dev swp1


The Mako template code in /etc/network/interfaces is incorrectly commented.


Comment the Mako code as documented in the Mako documentation, using double hash instead of a single hash.

If you do the following:

# %for I in [1,10]:
#   auto br${I}
#   iface br${I} inet static
#     bridge_ports swp11.$I swp10.$I
# %endfor

Change it to:

## %for I in [1,10]:
##   auto br${I}
##   iface br${I} inet static
##     bridge_ports swp11.$I swp10.$I
##  %endfor
Have more questions? Submit a request


Powered by Zendesk