我在 netplan 配置中遇到了缩进不一致的问题。如果可能的话,我希望有人能向我解释我哪里出错了。谢谢。
错误是:
/etc/netplan/50-cloud-init.yaml:**46**:12: Invalid YAML: inconsistent indentation:
addresses: []
从这一行开始直到最后两个 VLAN 配置(eno3.220 和 eno3.230)结束,都被视为错误。
netplan配置如下:
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
答案1
您有许多 .yaml 错误... netplan 对间距、缩进(应该只有 2 个空格)非常挑剔,没有制表符...
注意:安装yamllint
以检查.yaml 文件。
sudo apt-get update
sudo apt-get install yamllint
这是当前的错误......但实际上还有更多......首先将所有缩进更改为 2 个空格,删除括号中的多余空格,将注释更改为“* 注释”......
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 代码通过了 lint...
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