2

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!

Jw9394
  • 23

2 Answers2

1

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

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
  • 32,237