Score:1

how to wirte a multiline text including space key to "late-commands" section in cloud-init "user-data" file

cz flag

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!

hr flag
This sounds like it would suit a [here document](https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Here-Documents). See for example [How to write multiple lines in one file from bash](https://askubuntu.com/questions/1269866/how-to-write-multiple-lines-in-one-file-from-bash).
Score:0
jp flag

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
Score:0
jp flag

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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.