bare provisioning with hostname based on MAC

63 views
Skip to first unread message

Nicolas Stojanovic

unread,
Nov 15, 2016, 11:04:38 AM11/15/16
to puppet-razor
Hi,

Sorry if the question was already answered, I didn't find it.

I'm looking to provision hundreds of physical servers with different hardware specs.
I need to link a specific hostname to something unique (serial number or MAC), this hostname we'll be used by puppet for the next stage
I could understood a hook could do this for me, but unfortunately no so fluent in json/ruby/....

The hook need to parse/access a file with corresponding matching.

Does someone have a hook already written that I could use and adapt a bit to match my specific environment?

that will be really helpful

Thanks
Nicolas



Scott McClellan

unread,
Nov 17, 2016, 3:12:47 PM11/17/16
to puppet-razor
Hi Nicolas,

Aside from the existing Ruby hook, I'm not aware of any other existing hooks for that purpose, so you'd need to write one specifically for your needs. Fortunately, you can write it in any executable language and the contract for how it gets executed is documented here.

The gist for what the script needs to output is here:

And since your use case seems primarily based on info that is sent as input, this is what the input structure looks like:

Hope that helps get you started. Let me know if you need any more assistance.

Scott

--
You received this message because you are subscribed to the Google Groups "puppet-razor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-razor...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at https://groups.google.com/group/puppet-razor.
For more options, visit https://groups.google.com/d/optout.
--
-- 

Nicolas Stojanovic

unread,
Dec 16, 2016, 1:11:17 AM12/16/16
to puppet-razor
Thanks for this.

I did a dig into the hook function but still struggling to have something that works.

Lets explain. I'd like to know which node was calling the hook and extract some facts about it to allow me to provide the right hostname. Facts are Mac/uuid/serial number.

I Wonder how to have them when the hook is called.


By the way I tried to do this kind of query on the api

/api/collections/nodes?uuid=xxxxxxx to have the node name but got an empty result.

Many thanks for your help.
Nicolas

Scott McClellan

unread,
Dec 16, 2016, 1:35:14 AM12/16/16
to puppet-razor

Hi Nicholas,

How this would work is that when the node boots and contacts Razor, reporting its facts for the first time, the Razor server will run the hook script with filename "node-registered". When that hook script gets triggered, it is passed as input via STDIN the data that you want about the node. An example of a script reading this input is here (this is ruby):

https://github.com/puppetlabs/razor-server/blob/master/hooks/hostname.hook/node-bound-to-policy#L5

"Extracting the facts about the node" would consist of the hook script reading this STDIN, parsing that string (it's sent as JSON), then pulling out the facts you want. The script can calculate what you'd like the hostname to be, and then needs to output (using `echo`, for example) this hostname you want, also in the correct JSON format. The JSON format for output is described by the docs in my past email. The simplest output script to change the "hostname" metadata value on a node would be (this is just bash):

cat <<EOF
{ "node": { "metadata": { "hostname": "some-hostname" } } }
EOF

Hope that helps! If you need more assistance, I'll need to know the language you're using to write the script (and maybe code fragments) to help more effectively.

Scott


--
You received this message because you are subscribed to the Google Groups "puppet-razor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-razor...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at https://groups.google.com/group/puppet-razor.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages