我正在尝试编写一个user-data
文件,以便可以同时部署许多 ubuntu 服务器。但现在我被困在该late-commands
部分。我正在尝试netplan
向01-network-manager-all.yaml
文件添加配置。它是一个yaml
文件,所以我必须保留空格键并输入多行文本。我尝试逐行
echo "" >> 01-network-manager-all.yaml
执行此操作。有没有办法同时插入多行文本?谢谢!
答案1
类似以下代码片段的自动安装将删除安装程序生成的网络配置并使用编写自定义网络配置late-commands
。
#cloud-config
autoinstall:
late-commands:
- |
rm /target/etc/netplan/00-installer-config.yaml
cat <<EOF > /target/etc/netplan/01-network-manager-all.yaml
network:
version: 2
ethernets:
zz-all-en:
match:
name: "en*"
dhcp4: true
zz-all-eth:
match:
name: "eth*"
dhcp4: true
EOF
也可以看看
答案2
有没有办法可以同时插入多行文本?
是的,很多......在猛击(Ubuntu 中的默认登录 shell),使用以下几个示例:
此处提供文档
$ cat << 'EOF' > file
Line one
Line two
Line three
Line four
EOF
$ cat file
Line one
Line two
Line three
Line four
printf
$ printf '%s\n' \
'Line one' \
' Line two' \
' Line three' \
'Line four' \
> file
$ cat file
Line one
Line two
Line three
Line four
或者
$ printf '%s\n' \
'Line one
Line two
Line three
Line four' \
> file
$ cat file
Line one
Line two
Line three
Line four
echo
$ echo -e \
'Line one\n'\
' Line two\n'\
' Line three\n'\
'Line four' \
> file
$ cat file
Line one
Line two
Line three
Line four
或者
$ echo \
'Line one
Line two
Line three
Line four' \
> file
$ cat file
Line one
Line two
Line three
Line four