This is an unfortunate consequence of yaml parsing rather than a bug in cloud-init. Since you're using plain unquoted strings, the quotes don't carry any special meaning and the ' #' is interpreted as the beginning of a comment.
This is specifically called out in the yaml spec at https://yaml.org/spec/1.2.2/#733-plain-style : "Plain scalars must never contain the “: ” and “ #” character combinations. Such combinations would cause ambiguity with mapping key/value pairs and comments." A few ways to work around this would be to quote the entire string or use the runcmd list syntax. E.g.,: #cloud-config runcmd: - "echo ' ############' > /etc/motd" - ["echo", " ############", ">", "/etc/motd"] I'm going to set the status as Invalid, but if there is something that I missed or you still believe this represents a bug in cloud-init, please do set it back to New and provide additional explanation. ** Changed in: cloud-init Status: New => Invalid -- You received this bug notification because you are a member of Yahoo! Engineering Team, which is subscribed to cloud-init. https://bugs.launchpad.net/bugs/1977780 Title: cloud-init appears to fail to run echo commands in runcmd that have whitespace before alphanumeric characters Status in cloud-init: Invalid Bug description: I've managed to reproduce using multipass and KVM on a local machine. To reproduce this you just need to have echo command in runcmd section of a cloud-init config file that have white space before any alphanumeric characters. For example the following runcmd stanza successfully updates /etc/motd: runcmd: - echo '############' > /etc/motd - echo 'Test Message' >> /etc/motd The follow runcmd stanza fails to execute the commands: runcmd: - echo ' ############' > /etc/motd - echo ' Test Message' >> /etc/motd These fail to run whether there is a single quotation mark or double quotation mark. It also appears to fail if it's a tab rather than a space, e.g. \t Not sure what logs to provide here, the cloud-init logs inside the VM are probably the most pertinent I would suspect as in both cases the VM build completes, it's just the commands are not run in one case, but I suspect the following lines in the cloud-init-output.log file in /var/log may be relevant: /var/lib/cloud/instance/scripts/runcmd: 12: Syntax error: Unterminated quoted string 2022-06-06 06:09:45,045 - cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts) 2022-06-06 06:09:45,045 - util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_scripts_user.py'>) failed To manage notifications about this bug go to: https://bugs.launchpad.net/cloud-init/+bug/1977780/+subscriptions -- Mailing list: https://launchpad.net/~yahoo-eng-team Post to : [email protected] Unsubscribe : https://launchpad.net/~yahoo-eng-team More help : https://help.launchpad.net/ListHelp

