Hey, Rafael!

Cloud-Init doesn't execute commands in runcmd section? There's a fix for that...

Introduction

Rafael

Rafael


til aws

Cloud-Init doesn't execute commands in runcmd section? There's a fix for that...

Posted by Rafael on .
Featured

til aws

Cloud-Init doesn't execute commands in runcmd section? There's a fix for that...

Posted by Rafael on .

Recently I've been working with cloud-config templates and custom Amazon Linux instances on AWS, when I ran into a very weird issue: the commands I put under the runcmd section were not executed at the end of the Cloud-Init run. Weirder still was the fact the commands were written out to a shell script under /var/lib/cloud/instances/instance/scripts/runcmd.

As it turns out, from around version 0.7.5 (ish) of Cloud-Init onwards, the execution of the commands from runcmd is delegated to the cloud-final stage, which doesn't seem to run by default when you boot from a custom AMI (based on Amazon Linux, though I've seen some posts stating the same happens on Red Hat and Ubuntu). [Source]

To fix this, you need to ensure /etc/cloud/cloud.cfg has the following two lines (more items could be defined under cloud_config_modules):

...
cloud_config_modules:
 - runcmd
 - ...
Rafael

Rafael

View Comments...