cloud-init 修改 netplan 生成时的格式

cloud-init 修改 netplan 生成时的格式

默认情况下,cloud-init 在内部生成以下内容50-cloud-init.yaml

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 145.239.202.202/32
            - 2001:41d0:800:226f::3/128
            gateway4: 51.89.172.254
            gateway6: 2001:41d0:800:22ff:ff:ff:ff:ff
            match:
                macaddress: 02:00:00:ff:3b:ea
            nameservers:
                addresses:
                - 213.186.33.99
                search: []
            set-name: eth0

但是我需要添加路由:到文件以使网络正常运行(OVH)

50-cloud-init.yaml

network:
    version: 2
    ethernets:
        eth0:
            addresses:
            - 145.239.202.202/32
            - 2001:41d0:800:226f::3/128
            gateway4: 51.89.172.254
            gateway6: 2001:41d0:800:22ff:ff:ff:ff:ff
            match:
                macaddress: 02:00:00:ff:3b:ea
            nameservers:
                addresses:
                - 213.186.33.99
                search: []
            set-name: eth0
            routes:
            - to: 51.89.172.254/32
              via: 0.0.0.0
              scope: link
            - to: 2001:41d0:800:22ff:ff:ff:ff:ff
              scope: link

唯一的区别是在底部添加了以下内容:

        routes:
        - to: 51.89.172.254/32
          via: 0.0.0.0
          scope: link
        - to: 2001:41d0:800:22ff:ff:ff:ff:ff
          scope: link

我如何修改 cloud-init 模板以便默认添加它,这样如果我重新运行cloud-init init它就不会删除它。

相关内容