Question

I have this part of my template:

            "UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
              "sudo yum update -y\n",
              "sleep 30\n",
              "sudo mkdir /data \n",
              "cd /data/\n"
                  ]]}}

for the server. It seems to execute the first line (since I can use wget) but doesn't do the 3rd or 4th lines. Any thoughts? Thanks!

Was it helpful?

Solution

The user-data is not run as a script unless the first two characters are #!

Try adding the following as the first line of the user-data so that CloudInit knows to run it as a shell script:

#!/bin/sh

As Rico points out, you can drop the sudo because user-data scripts are run as root on the first boot of the instance.

Also, the sleep 30 and cd /data/ are not providing any benefit if this is the entirety of the user-data script.

This would result in code like:

"UserData"       : { "Fn::Base64" : { "Fn::Join" : ["", [
    "#!/bin/sh\n",
    "yum update -y\n",
    "mkdir /data \n",
]]}}

You could add the cd back in if there are further statements you are adding to the user-data script.

OTHER TIPS

You can check your /var/log/cloud-init.log to see what's going on. I don't think you need sudo since cloudinit stuff is run as root.

Also did you try:

"mkdir /data\n"

With no space between '/data' and '\n'?

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top