7

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?

1
  • 1
    Not sure it deserves a separate answer, but note that the message may appear due to missing a netplan-specific element even though YAML per se is valid. E.g. I had the error after forgetting a addresses word after nameservers, and rather passing the array directly.
    – Hi-Angel
    Nov 7, 2022 at 13:30

6 Answers 6

8

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

1
  • if you add a second device under ethernets, you may be able to configure that new network device to both dhcp4: false and dhcp6: false. in other words, it may be the initial network device which needs DHCP.
    – noobninja
    Jan 23, 2020 at 21:31
3

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
2
  • I don't think there's an error. I copied the code from question to a online YAML linter and it says it's a valid yaml 🤷‍♂️
    – Hi-Angel
    Nov 7, 2022 at 13:06
  • this worked for me and is addressing the error message presented, rather than claiming the debug is useless Mar 28, 2023 at 18:09
1

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
1
  • I know it's old, but: 192.168.0/24 is not a valid IP address.
    – Kevin
    Aug 15, 2023 at 12:59
0

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

https://netplan.io/examples

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.

0
0

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.

0

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

You must log in to answer this question.

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