salt-cloud, EC2's "user-data" and startup customization

332 views
Skip to first unread message

Jonathan Ballet

unread,
Nov 9, 2015, 9:10:36 AM11/9/15
to Salt-users
Hi,

I'm looking for a way to setup as early as possible some settings on my new minion instantiated on AWS EC2, and in particular setting up the hostname.

I'm currently creating these instances via salt-cloud and the ec2 driver, and I'm using an AMI which is launching "cloud-init" at startup time. When I run my highstate on the new instances, on the first thing I'm doing is to set up the hostname, but grains don't get reloaded after that, and grains['fqdn'] is still giving the original name given by AWS until I run a second highstate. And so for a while, I got minions which have a seemlessly random hostname which is used by some applications, until the second highstate finished and everything is in order again.

So, I thought I could use the cloud-init package and passing the related hostname settings into the instance's "user-data". Apparently, passing user-data is now supported, although it's not documented (cf. https://github.com/saltstack/salt/issues/12072#issuecomment-151155379).

I wonder however how I could set different user-data per-minion, using salt-cloud? Is there a way to configure the new instances configuration from salt-cloud? I can't find this anywhere in the documentation. What I'm looking to do is to have a salt-cloud profile definition with a way to say "this value here is the minion ID which I'm creating a new instance", or something similar.

Thanks for your help!

 Jonathan

Dani C

unread,
Dec 20, 2015, 3:19:26 AM12/20/15
to Salt-users
I doubt you can do this since the user_data is added into the provider and even if you use the cloud map file will still reference the same provider.

One option i believe (although not tested) is to try and get the user_data out of provider file and stick it into profiles where each profile is targeting same group of minions with same user data file (not ideal but better than nothing)

Dani

DAVID TAYLOR

unread,
Feb 12, 2016, 11:02:27 AM2/12/16
to Salt-users
This is what I use in my userdate to install install salt and create a custom hostname for my aws instances.  Hope this helps you

<powershell>
Read-S3Object -BucketName np-tree-operations/latest/ops/salt/binaries -Key Salt-Minion-2015.8.1-AMD64-Setup.exe -File s:\tasks\salt\Salt-Minion-2015.8.1-AMD64-Setup.exe
$instanceId = Invoke-WebRequest "http://169.254.169.254/latest/meta-data/instance-id" -UseBasicParsing | % {$_.Content} | select -first 1
$nodename = "dev-web-mccr-"+$instanceId
& s:\tasks\salt\Salt-Minion-2015.8.1-AMD64-Setup.exe /S /master=172.17.14.15 /minion-name=$nodename /start-service=1

</powershell>
Reply all
Reply to author
Forward
0 new messages