Netplan Error in Network Definition Expected Mapping
No Way to Make the Network Works on the New Ubuntu Server. This Is the Netplan Yaml File: # to Disable Cloud-Init's Network Configuration Capabilities, Write a...
no way to make the network works on the new ubuntu server. This is the netplan yaml file:
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config:disabled}
network:
version: 2
ethernets:
enp0s3:
addresses: [192.168.0.183/24]
gateway4: 192.168.0.250
dhcp4: false
nameservers:
addresses: [8.8.8.8,8.8.4.4]
optional: true
running netplan --debug apply I get:
Error in network definition //etc/netplan/50-cloud-init.yaml line 1 column 1: expected mapping
I'm going crazy, it was so simple before! Why doesn't work? what does it mean this error?
6 Answers
removing dhcp4 setting fixed the issue...who knows!
maybe because if you enable the dhcp you have to set it to "true" and if you disable you have to set to "no"? I really hope not!!
debug info completely useless
a netplan configuration is base on yaml, when looking your configuration. i think the indentation is error because its have 3 space. maybe you can try this
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config:disabled}
network:
version: 2
ethernets:
enp0s3:expected mapping
addresses: [192.168.0.183/24]
gateway4: 192.168.0.250
dhcp4: false
nameservers:
addresses: [8.8.8.8,8.8.4.4]
optional: true
I always configure for a static ip the "dhcp" with the value of "no" like this
dhcp4: no
See an example below
network:
ethernets:
enp0s3:
dhcp4: no
dhcp6: no
addresses: [10.4.1.174/21]
gateway4: 10.5.1.6
nameservers:
addresses: [8.8.4.4,8.8.8.8]
routes:
- to: 192.168.0/24
via: 10.5.0.1
metric: 100
version: 2
My first time coming across this new way of networking and the "expected mapping" error. It's a nice one.
I got a static IP working by editing etc/netplan/50-cloud-init.yaml but found that it was SUPER picky about the layout (spaces).
I used the examples given at
By going to the line BEFORE the line mentioned in the error (given when it didn't work) and pressing "return", a new line and the correct amount of indent was automatically inserted.
Restated... I had an error reported in line 12, so I went to the end of line 11 and pressed "return". A carriage return AND the (presumably) correct amount of indentation was automatically inserted.
If the error was at line 1 (as for the OP) I can only guess that the syntax is wrong.
I learned that if the indents are not perfect, it does not work. Even though I went off another example, the example I found was incorrect. Here's the contents of 00-installer-config.yaml that worked for me in case it helps someone else later:
network:
ethernets:
enol:
dhcp4: no
addresses: [192.168.0.45/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8, 8.8.8.4]
version: 2
Here is a screenshot of 00-installer-config.yaml.
I tried several formats
Ubuntu 20 (netplan apply command) only accepted config after I configured exact spaces before each line:
# This is the network config written by 'subiquity'
network:
version: 2
renderer: networkd
ethernets:
ens18:
addresses: [172.16.1.95/24]
gateway4: 172.16.1.1
nameservers:
addresses: [8.8.8.8/32, 8.8.4.4/32]
After that, error went away and I was able to connect to 172.16.1.95 server via SSH