i am trying to write a user-data file so i could deploy many ubuntu server at the same time. but now i am stuck at the late-commands section. i am trying to add a netplan configuration to 01-network-manager-all.yaml file. it is a yaml file so i have to keep the space key and input multiline text. i tried using
echo "" >> 01-network-manager-all.yaml
doing this line by line. is there any way to insert multiline text at the same time? thanks!
Asked
Active
Viewed 1,395 times
3
Jw9394
- 33
2 Answers
2
An autoinstall like the following snippet will delete the installer generated network config and write a custom network config using 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
see also
Andrew Lowther
- 7,251
0
Is there any way to insert multiline text at the same time?
Yes, plenty ... In Bash(The default login shell in Ubuntu), a few examples using:
Here Document
$ 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
or
$ 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
or
$ echo \
'Line one
Line two
Line three
Line four' \
> file
$ cat file
Line one
Line two
Line three
Line four
Raffa
- 34,963