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

Follow

Issue

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>
    main(sys.argv)
  File "/sbin/ifup", line 328, in main
    handlers.get(op)(args)
  File "/sbin/ifup", line 43, in run_up
    printdependency=args.printdependency)
  File "/usr/lib/python2.7/dist-packages/ifupdown/ifupdownmain.py", line 669, in up
    self.read_iface_config()
  File "/usr/lib/python2.7/dist-packages/ifupdown/ifupdownmain.py", line 423, in read_iface_config
    return self.read_default_iface_config()
  File "/usr/lib/python2.7/dist-packages/ifupdown/ifupdownmain.py", line 420, in read_default_iface_config
    nifaces.load()
  File "/usr/lib/python2.7/dist-packages/ifupdown/networkinterfaces.py", line 264, in load
    return self.read_file(filename)
  File "/usr/lib/python2.7/dist-packages/ifupdown/networkinterfaces.py", line 260, in read_file
    filedata = self.run_template_engine(filedata)
  File "/usr/lib/python2.7/dist-packages/ifupdown/networkinterfaces.py", line 244, in run_template_engine
    return t.render()
  File "/usr/lib/python2.7/dist-packages/mako/template.py", line 397, in render
    return runtime._render(self, self.callable_, args, data)
  File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 764, in _render
    **_kwargs_for_callable(callable_, data))
  File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 796, in _render_context
    _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
  File "/usr/lib/python2.7/dist-packages/mako/runtime.py", 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/runtime.py", 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
address 10.1.2.2
netmask 255.255.255.252
down ip addr flush dev swp1

Cause

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

Resolution

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

Comments

Powered by Zendesk