does linode support cloud init on linode creation?

I cant find any info, I really would like to be able to pass user-data to cloud init when linode is created, is this possible or are we limited to stackscripts?

9 Replies

Hello Marketsys,

Can you clarify what you mean by "pass user-data to cloud init when linode is created"? Like, what is the exact process?

If I do understand correctly, though, you're trying to automate deploying servers, which is something that can be done using stackscripts as you suspected. There are other tools that can help with this on our platform as well, such as Vagrant:

https://www.linode.com/docs/application … vironments">https://www.linode.com/docs/applications/configuration-management/vagrant-linode-environments

If I'm off the mark or if you need a bit more information please let me know!

@dwfreed:

Stackscripts are already run-only-once. This is implemented by moving aside the getty binary, and putting a small script in its place which executes your stackscript, then puts the getty binary back and then executes that (this is why they run after all initscripts). It looks like you'd just run 'cloud-init modules –mode config cloud-config.yml' where 'cloud-config.yml' contains your config (which you can have the StackScript take as input in the Linode Manager/API and then inject that into a file).

Awesome! I'll give that a try, thank you!

After having to dive into the source code to figure out how cloud-init actually works, because their documentation is completely worthless in this regard, it looks like you could make a simple StackScript to install cloud-init, dump your desired config into a file, and then initiate cloud-init with that file.

@dwfreed:

it looks like you could make a simple StackScript to install cloud-init, dump your desired config into a file, and then initiate cloud-init with that file.

That's what I was thinking about, but cloud-init runs once on the first boot of custom images (EC2 also has support for cloud-config directly into the panel when creating images), so I still didn't find how to actually install and run it on 1st boot manually.

For manually running it, there are these 2 not-so-helpful topics (and nothing in the official docs):

http://stackoverflow.com/questions/2315 … t-manually">http://stackoverflow.com/questions/23151425/how-to-run-cloud-init-manually

http://stackoverflow.com/questions/6475 … ance-boots">http://stackoverflow.com/questions/6475374/how-do-i-make-cloud-init-startup-scripts-run-every-time-my-ec2-instance-boots

But I still didn't find where I would place the cloud-config.yml file and still didn't find out how to run ONLY my script once.

Stackscripts are already run-only-once. This is implemented by moving aside the getty binary, and putting a small script in its place which executes your stackscript, then puts the getty binary back and then executes that (this is why they run after all initscripts). It looks like you'd just run 'cloud-init modules –mode config cloud-config.yml' where 'cloud-config.yml' contains your config (which you can have the StackScript take as input in the Linode Manager/API and then inject that into a file).

@sohsoh5:

Hello Marketsys,

Can you clarify what you mean by "pass user-data to cloud init when linode is created"? Like, what is the exact process?

If I do understand correctly, though, you're trying to automate deploying servers, which is something that can be done using stackscripts as you suspected. There are other tools that can help with this on our platform as well, such as Vagrant:

https://www.linode.com/docs/application … vironments">https://www.linode.com/docs/applications/configuration-management/vagrant-linode-environments

If I'm off the mark or if you need a bit more information please let me know!

He is referring to providing Cloud-Config to the cloud-init application that is available on Ubuntu (edited: not only Ubuntu). It is different from Stack Scripts. I'm also looking for this, because I'm considering moving from DO to Linode.

Digital Ocean supports that as "droplet metadata" (they call "User Data"): when you are creating a droplet, in the web panel you paste your cloud-config data and it is run automatically on droplet creation.

https://www.digitalocean.com/community/ … -scripting">https://www.digitalocean.com/community/tutorials/an-introduction-to-cloud-config-scripting

https://www.digitalocean.com/community/ … t-metadata">https://www.digitalocean.com/community/tutorials/an-introduction-to-droplet-metadata

This is part of one of my "User Data" that I use when automatically deploying nodes for CI. Does Linode support something like that?

~~![](<URL url=)http://i.imgur.com/IcsABbK.png" />

#cloud-config

swap:
 size: auto
 filename: /swapfile
 maxsize: 4G

users:
  - name: gitlab-runner
    ssh-authorized-keys:
      - <your_key1>
      - <your_key2>
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    groups: sudo
    shell: /bin/bash

write_files:
  - path: /etc/systemd/system.conf.d/10-default-env.conf
    content: |
      [Manager]
      DefaultEnvironment=LC_ALL=en_US.UTF-8
  - path: /etc/profile.d/env.sh
    content: |
      export LC_ALL=en_US.UTF-8

runcmd:
  - sed -i -e '/^PermitRootLogin/s/^.*$/PermitRootLogin no/' /etc/ssh/sshd_config
  - sed -i -e '$aAllowUsers gitlab-runner' /etc/ssh/sshd_config
  - service ssh restart
  - update-locale LC_ALL=en_US.UTF-8</your_key2></your_key1>

~~

@jamix:

For us, a big disadvantage of Stackscripts is that you can't deploy an image with them. DigitalOcean allows you to deploy a master image via the API and then do any extra customizations with cloud-config. This is also discussed here: https://forum.linode.com/viewtopic.php?f=20&t=11899

Why not clone a gold image then use a script to customize it? You can skip all the vagrant/puppet/salt/ansible crap then.

For us, a big disadvantage of Stackscripts is that you can't deploy an image with them. DigitalOcean allows you to deploy a master image via the API and then do any extra customizations with cloud-config. This is also discussed here: https://forum.linode.com/viewtopic.php?f=20&t=11899

I realize this conversation has gone stale, but for the sake of anyone that visits this..

I created a StackScript that takes a userdata variable (which must be a base64 encoded userdata file).

https://www.linode.com/stackscripts/view/392559

$ pip install linode-cli
$ read -s -p "password: " ROOT_PASS; echo
$ linode-cli linodes create \
    --root_pass=${ROOT_PASS} \
    --label=cloudinittest \
    --stackscript_id=392559 \
    --stackscript_data='{"userdata":"'$(base64 -i /tmp/user-data)'"}'

The implementation is similar to @dwfreed's recommendation :-D

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct