D6dfa6aab25a587d80c4e75b70233550ba136ebb
By:
NicolaDL

cURL in user_data

June 16, 2017 171 views
Getting Started DigitalOcean Ubuntu 16.04

Hello guys,
I'm currently trying to use this value for user_data:

#cloud-config
runcmd:
  - curl https://mysupercooldomain.tld/do.sh | sh

The content of do.sh is:

#!/bin/bash
echo "doing" > status
dpkg --add-architecture i386
apt-get -y update
apt-get -y install mailutils postfix curl wget file bzip2 gzip unzip bsdmainutils python util-linux ca-certificates tmux lib32gcc1 libstdc++6 libstdc++6:i386
adduser --disabled-password --gecos "Game Server" gameserver
su - gameserver
wget https://mysupercooldomain.tld/gameserver
chmod +x gameserver
./gameserver install

After creating a Droplet, the Droplet does not contain the data it should contain.

Something wrong?

1 Answer
hansen June 16, 2017
Accepted Answer

Hi @NicolaDL

Try encapsulating it in single quotes ', since it will then write the string to a temporary file and execute that file with sh. And since it's a bash script, you can parse it directly to bash instead of sh.

#cloud-config
runcmd:
  - 'curl https://mysupercooldomain.tld/do.sh | /bin/bash -s'
  • It works! Marked as Accepted.

    Just a quick note: I noticed that cloud-config works only on Ubuntu 14.04 and not in newer versions.

    Thanks for your time :D

    • @NicolaDL I've tested cloud config a couple of days ago on Ubuntu 16.04 and FreeBSD 11, and it was working on both with runcmd.
      Have a look at the error log for any issues /var/log/cloud-init.log and /var/log/cloud-init-output.log

Have another answer? Share your knowledge.