Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Invalid YAML: inconsisten indentation

  1. #1
    Join Date
    Apr 2023
    Beans
    95

    Invalid YAML: inconsisten indentation

    Hello,
    I've only used spaces, no tabs and the indentation looks correct.
    I even screencast the typing of the new file and all I do is backspace twice?
    Can't attach the screencast.webm 830.3 kB file.

    Code:
    ubuntu@ubuntu:/etc/netplan$ ls
    01-netcfg.yaml  01-netcfg.yaml.202312022204  01-netcfg.yaml.origin  01-network-manager-all.yaml
    ubuntu@ubuntu:/etc/netplan$ cat 01-netcfg.yaml
    network:
      network:
        version: 2
        renderer: networkd
        ethernets:
          enp2s0:
            dhcp4: false
            dhcp6: false
            link-local []
          enp3s0:
            dhcp4: false
            dhcp6: false
            link-local []
          bridges:
            br0:
              interfaces: [enp3s0]
              dhcp4: false
              dhcp6: false
              link-local []
              macaddress: a8:a1:59:6e:1f:8b
              parameters:
                stp: false
            br1:
              interfaces: [enp2s0]
              dhcp4: false
              dhcp6: false
              link-local []
              addresses: [192.168.1.120/24]
              macaddress: 1c:61:b4:6d:38:4f
              routes:
                - to: default 
                  via: 192.168.1.170
                nameservers:
                  addresses: [8.8.8.8]
                parameters:
                  stp: false
    ubuntu@ubuntu:/etc/netplan$ sudo netplan apply
    [sudo] password for ubuntu: 
    /etc/netplan/01-netcfg.yaml:10:7: Invalid YAML: inconsistent indentation:
          enp3s0:
          ^

  2. #2
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Invalid YAML: inconsisten indentation

    Delete the 2nd

    Code:
      network:
    line. Also, the
    Code:
          bridges:
    line and everything inside it is on the wrong level. Needs to be on the same level as "ethernets".

  3. #3
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,699

    Re: Invalid YAML: inconsisten indentation

    I also think that all the lines "link-local []" should have a colon: "link-local: []"

  4. #4
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Invalid YAML: inconsisten indentation

    Quote Originally Posted by The Cog View Post
    I also think that all the lines "link-local []" should have a colon: "link-local: []"
    Or just remove them. Are they required now? None of my netplan files has any mention of local-link.

  5. #5
    Join Date
    Jul 2021
    Beans
    76

    Re: Invalid YAML: inconsisten indentation

    Try using a YAML validator - like at

    https://appdevtools.com/yaml-validator

    or

    https://yamlchecker.com/

  6. #6
    Join Date
    Apr 2023
    Beans
    95

    Re: Invalid YAML: inconsisten indentation

    Thanks for the feedback.
    I'll try removing the link-local: [] lines after the other errors are cleared, as the file works on SSD1 (/dev/sda), but I'm testing installing on SSD2 (/dev/sdb).
    The YAML validators say the code is good after editing your suggestions.
    However on my machine, the error appears:
    Code:
    ubuntu@ubuntu:/etc/netplan$ ls
    01-netcfg.yaml  01-netcfg.yaml.202312022204  01-netcfg.yaml.origin  01-network-manager-all.yaml
    ubuntu@ubuntu:/etc/netplan$ cat 01-netcfg.yaml
    network:
      version: 2
      renderer: networkd
      ethernets:
        enp2s0:
          dhcp4: false
          dhcp6: false
          link-local: []
        enp3s0:
          dhcp4: false
          dhcp6: false
          link-local: []
        bridges:
          br0:
            interfaces: [enp3s0]
            dhcp4: false
            dhcp6: false
            link-local: []
            macaddress: a8:a1:59:6e:1f:8b
            parameters:
              stp: false
          br1:
            interfaces: [enp2s0]
            dhcp4: false
            dhcp6: false
            link-local: []
            addresses: [192.168.1.120/24]
            macaddress: 1c:61:b4:6d:38:4f
            routes:
              - to: default 
                via: 192.168.1.170
            nameservers:
              addresses: [8.8.8.8]
            parameters:
              stp: false
    ubuntu@ubuntu:/etc/netplan$ sudo netplan apply
    /etc/netplan/01-netcfg.yaml:14:7: Error in network definition: unknown key 'br0'
          br0:
          ^

  7. #7
    Join Date
    Jul 2013
    Location
    Wisconsin
    Beans
    4,952

    Re: Invalid YAML: inconsisten indentation

    bridges: and everything it contains should be reduced two spaces. @TheFu told you this in Post #2.

    bridges: is not subordinate to ethernets:
    Last edited by ian-weisser; December 3rd, 2023 at 04:19 AM.

  8. #8
    Join Date
    Feb 2019
    Location
    Virginia
    Beans
    366
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: Invalid YAML: inconsisten indentation

    Quote Originally Posted by ian-weisser View Post
    bridges: and everything it contains should be reduced two spaces.

    bridges: is not subordinate to ethernets:
    Yep, that was my problem exactly recently with a YAML file involving a bridge. Spacing & alignment are not meaningless.

  9. #9
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,699

    Re: Invalid YAML: inconsisten indentation

    As TheFu pointed out in #2, the line containing word bridges and every line afterwards need their indent reducing by 2 spaces. At the moment, "bridges" looks like the name of a third ethernet, which it isn't. Also, routes, nameservers and parameters need outdenting (2 levels, I think) because at the moment they look like properties of br1.

    I find a 4-space indent is clearer to read than 2-spaces. This might be right for you. Not sure, but at least it's valid yaml:
    Code:
    network:
        version: 2
        renderer: networkd
        ethernets:
            enp2s0:
                dhcp4: false
                dhcp6: false
                link-local: []
            enp3s0:
                dhcp4: false
                dhcp6: false
                link-local: []
        bridges:
            br0:
                interfaces: [enp3s0]
                dhcp4: false
                dhcp6: false
                link-local: []
                macaddress: a8:a1:59:6e:1f:8b
                parameters:
                    stp: false
            br1:
                interfaces: [enp2s0]
                dhcp4: false
                dhcp6: false
                link-local: []
                addresses: [192.168.1.120/24]
                macaddress: 1c:61:b4:6d:38:4f
        routes:
            - to: default
              via: 192.168.1.170
        nameservers:
            addresses: [8.8.8.8]
        parameters:
            stp: false

  10. #10
    Join Date
    Apr 2023
    Beans
    95

    Re: Invalid YAML: inconsisten indentation

    Thanks, all fixed. I like the 4 space indent to fool proof these errors OR perhaps the 2 YAML code checker websites might do it.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •