1

I use following command in my ubuntu auto-install late-commands to append a line in my /etc/aliases file:

sed -i -e '/^postmaster:.*/i\'$'root:           root' /target/etc/aliases

I also tried POSIX not conform version:

sed -i '/^postmaster:.*/i root:           root' /target/etc/aliases

Both with the same result while installing:

finish: subiquity/Late/load_autoinstall_data: {"sed -i -e '/^postmaster:.*/i\\'$'root": "root' /target/etc/aliases"} is not of type 'string', 'array'

I think I understand the issue: The Column-Space is interpreted by yaml or something else as yaml entry. At least this message leads in my opinion to this problem.

I thought since late-commands are already multiline commands this would not be any issue.

I also tried using double quotes instead of single quotes.

Any Idea how to achieve the wanted behaviour?

MaKaNu
  • 111

1 Answers1

1

I thought since late-commands are already multiline commands this would not be any issue.

Why do you think this? It sounds like you are using a single-line of YAML and thinking it will behave like multiline YAML.

I was able to use this YAML multiline syntax without any errors

#cloud-config
autoinstall:
  late-commands:
    - |
      sed -i '/^postmaster:.*/i root:           root' /target/etc/aliases
      true

I use true at the end of the command so that if sed exits with a non-zero return code then it will not stop the installer from continuing. For example, if /target/etc/aliases does not exist.

see also

notes

There did appear to be some syntax/escaping issue with the dollar sign. When I tried this configuration

#cloud-config
autoinstall:
  late-commands:
    - |
      cat <<EOF > /run/aliases
      postmaster:root
      EOF
      sed -i -e '/^postmaster:.*/i\'$'root:           root' /run/aliases
      sed -i '/^postmaster:.*/i root:           root' /run/aliases
      true

The resulting /run/aliases file content was

$root:           root
root:           root
postmaster:root

I tested using Ubuntu 22.04 (subiquity 22.04.2)

  • Why do you think this? I didn't just used a single command. I've added a list of command with - <command1>\n - <commander2>. I didn't know that nesting is still possible with this syntax.

    – MaKaNu Aug 27 '22 at 09:34
  • Still wondering, that it ignored the single quotes. Seems to be the same issue in the other question. I am also not sure if the true is reasonable, since if /etc/aliases is not existence postfix isn't installed. – MaKaNu Aug 27 '22 at 09:39