5

Doing a clean install of Ubuntu Server 18.04 on a new machine. Currently attempting to configure my Ethernet network interface to use DHCP using netplan.

My config file, dynamic.yaml, reads as follows:

network:
    version: 2
    renderer: networkd
    ethernets:
        eno1:
            dhcp4: true

When I attempt to load this configuration with

sudo netplan try

I get an error which reads:

Error while loading /etc/netplan/dynamic.yaml, aborting.
sudo netplan --debug try

merely prints out "ERROR:Error while loading /etc/netplan/dynamic.yaml, aborting."

Any ideas what the error is? Or does anyone have any suggestions for how to get netplan to actually specify what the error is?

4
  • 1
    The netplan-try manual page suggests there's a --debug switch: have you tried sudo netplan --debug try? Aug 24, 2019 at 15:50
  • 1
    Merely says the same thing unfortunately Aug 24, 2019 at 15:58
  • 1
    Does sudo netplan --debug generate give any more clues?
    – heynnema
    Aug 24, 2019 at 16:50
  • Inspect your file with od -bc /etc/netplan/dynamic.yaml. Check for TABs, spaces, End-Of-Line, spurious ^M, bytes > 128. Didn't we learn from Makefile syntactic sensitivity?
    – waltinator
    May 12, 2022 at 18:01

2 Answers 2

8

netplan is VERY fussy about .yaml file formatting. No tabs, specific indentation, and no extra spaces. Your .yaml looks ok syntactically, but try this variation...

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: true

sudo netplan generate # generate config files

sudo netplan apply # apply config

reboot # reboot the computer

4
  • 3
    Turns out I was using tabs instead of spaces - switching to spaces fixed the issue, Thanks! Aug 24, 2019 at 17:19
  • @heynnema, this answer made me get out my glasses and find the issue in my netplan -- tedious. Is there a YAML parsing utility (any language) that you know of to find issues programmatically?
    – Todd Curry
    Mar 8, 2022 at 20:25
  • 3
    @ToddCurry Check out yamllint. It's in the Ubuntu repos.
    – heynnema
    Mar 8, 2022 at 20:30
  • 1
    Brilliant, @heynnema -- thank you! When I googled, I also found yamllint.com, (which may/may not be secure, but) checks your yaml in a web form. You have set me on a path to yaml sanity!
    – Todd Curry
    Mar 9, 2022 at 21:24
1

Everybody should try yamllint. It helps you write a proper formatted yaml file. Install sudo apt install yamllint.

Then check your file:

yamllint /etc/netplan/01-network-manager-all.yaml
01-network-manager-all.yaml
  1:81      error    line too long (203 > 80 characters)  (line-length)
  1:202     error    trailing spaces  (trailing-spaces)
  2:8       error    syntax error: mapping values are not allowed here (syntax)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .