首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Netplan不一致缩进Ubuntu 20.04服务器

Netplan不一致缩进Ubuntu 20.04服务器
EN

Ask Ubuntu用户
提问于 2020-09-27 13:35:55
回答 1查看 11.5K关注 0票数 0

在netplan配置中,我有一个不一致的缩进问题。如果可能的话,我想找人向我解释我哪里出了问题。谢谢。

错误是:

代码语言:javascript
运行
复制
/etc/netplan/50-cloud-init.yaml:**46**:12: Invalid YAML: inconsistent indentation:
           addresses: []

从这一行到最后两个VLAN配置(eno3.220和eno3.230)的末尾,都被认为是一个错误。

netplan配置如下:

代码语言:javascript
运行
复制
network:
    version: 2
    ethernets:
        eno1:
            {}
        eno2:
            {}
        eno3:
            {}
        eno4:
            {}

    bonds:
        bond0:
            interfaces: [eno1, eno2]
            addresses: []
            parameters:
                mode: balance-alb
                mii-monitor-interval: 1
                gratuitious-arp: 5
                primary: eno1
            optional: false
    vlans:
        bond0.640:
            addresses: []
            dhcp4: false
            id: 640
            link: bond0
        bond0.1008:
            addresses: []
            dhcp4: false
            id: 1008
            link: bond0
        eno3.220:
           addresses: [] «-- **line 46**
           dhcp4: false 
           id: 220
           link: eno3
        eno3.230:
           addresses: []
           dhcp4: false
           id: 230
           link: eno3

    bridges:
        br0:
          interfaces: [bond0.1008]
          addresses: [ x.x.x.x/x ]
          dhcp4: false
          gateway4: x.x.x.1
          parameters:
              forward-delay: 0
          nameservers:
              addresses: [ x.x.x.x, y.y.y.y ]
              search: []
          optional: false
        br1:
          interfaces: [bond0.640]   «--- inactive at this moment
          #addresses: [ ]
          dhcp4: false
          #gateway4:
          parameters:
              forward-delay: 0
          #nameservers:
              #addresses: [ ]
              search: []
          optional: false
        br2:
          interfaces: [eno3.220]
          dhcp4: false
          addresses: [x.x.x.x/x]
          gateway4: x.x.x.1
          parameters:
              forward-delay: 0
          nameservers:
              addresses: [x.x.x.x, y.y.y.y]
              search: []
          optional: false
        br3:
          interfaces: [eno3.230] «-- inactive at this moment
          #addresses: []
          dhcp4: false
          #gateway4:
          parameters:
              forward-delay: 0
          #nameservers:
               #addresses: []
               #search: []
          optional: false
EN

回答 1

Ask Ubuntu用户

发布于 2020-09-27 13:54:37

您有许多.yaml错误..。网络计划是非常挑剔的间隔,缩进(应该只有两个空格),没有标签.

注意:安装yamllint检查.yaml文件。

sudo apt-get update

sudo apt-get install yamllint

以下是当前的错误..。但实际上还有更多..。从将所有缩进更改为2个空格开始,删除括号中的额外空格,将注释更改为"*注释“。

代码语言:javascript
运行
复制
  35:12     error    wrong indentation: expected 12 but found 11  (indentation)
  36:24     error    trailing spaces  (trailing-spaces)
  40:12     error    wrong indentation: expected 12 but found 11  (indentation)
  47:11     error    wrong indentation: expected 12 but found 10  (indentation)
  48:23     error    too many spaces inside brackets  (brackets)
  35:26     error    syntax error: expected <block end>, but found '<scalar>' (syntax)
  48:33     error    too many spaces inside brackets  (brackets)
  54:27     error    too many spaces inside brackets  (brackets)
  54:44     error    too many spaces inside brackets  (brackets)
  58:11     error    wrong indentation: expected 12 but found 10  (indentation)
  59:12     warning  missing starting space in comment  (comments)
  61:12     warning  missing starting space in comment  (comments)
  64:12     warning  missing starting space in comment  (comments)
  64:11     warning  comment not indented like content  (comments-indentation)
  65:16     warning  missing starting space in comment  (comments)
  69:11     error    wrong indentation: expected 12 but found 10  (indentation)
  80:11     error    wrong indentation: expected 12 but found 10  (indentation)
  81:12     warning  missing starting space in comment  (comments)
  83:12     warning  missing starting space in comment  (comments)
  86:12     warning  missing starting space in comment  (comments)
  87:17     warning  missing starting space in comment  (comments)
  87:16     warning  comment not indented like content  (comments-indentation)
  88:17     warning  missing starting space in comment  (comments)

这个.yaml代码通过林特..。

代码语言:javascript
运行
复制
network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      match:
        macaddress: xx:xx:xx:xx:xx:xx
    eno2:
      match:
        macaddress: xx:xx:xx:xx:xx:xx
    eno3:
      match:
        macaddress: xx:xx:xx:xx:xx:xx
    eno4:
      match:
        macaddress: xx:xx:xx:xx:xx:x
  bonds:
    bond0:
      interfaces: [eno1, eno2]
      parameters:
        mode: balance-alb
        mii-monitor-interval: 1
        gratuitious-arp: 5
        primary: eno1
  vlans:
    bond0.640:
      id: 640
      link: bond0
    bond0.1008:
      id: 1008
      link: bond0
    eno3.220:
      id: 220
      link: eno3
    eno3.230:
      id: 230
      link: eno3
  bridges:
    br0:
      interfaces: [bond0.1008]
      addresses: [x.x.x.x/x]
      gateway4: x.x.x.1
      parameters:
        forward-delay: 0
      nameservers:
        addresses: [x.x.x.x, y.y.y.y]
    br1:
      interfaces: [bond0.640]
      parameters:
        forward-delay: 0
    br2:
      interfaces: [eno3.220]
      addresses: [x.x.x.x/x]
      gateway4: x.x.x.1
      parameters:
        forward-delay: 0
      nameservers:
        addresses: [x.x.x.x, y.y.y.y]
    br3:
      interfaces: [eno3.230]
      parameters:
        forward-delay: 0

注:见https://netplan.io/examples/

票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1278127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档