Is there a way to pass a value on bootstrap


#1

Hello,
Very new to Chef and I am trying to figure out how to determine location of server - ex. azureeast, azurewest, awseast… I don’t see anything I can use from Ohai.
Is there a way at time of bootstrap that I can pass this info and then access from recipe?
For anyone familiar with Ansible - I was able to use a survey to accomplish.
Thanks for any ideas


#2

Well, if you know when you bootstrap it, you could add a role I think (and that role could contain an attribute that specified the region)

I thought that there was an ohai helper that could do this detection as well, but on that I am not positive.


#3

Thanks! Just ran across --json-attributes and that might be an option. Just need to understand how to use it…


#4

Couple of options

1. ohai hints

you could set a hint that specifies which datacenter it is in

2. Datacenter role

Have roles for each datacenter

- role[azure-east]
- role[azure-west]

A role can have any arbitrary values that you want, e.g.

{
  "role": "azure-east",
  "datacenter": "azure-east"
}

Then append the appropriate role to the server. This is the approach that we use.

3. Azure metadata service

Azure provides a metadata service at a non routable ip 169.254.169.254
You could use ruby to query this local ip for information about the server. It may be possible to find/write an ohai plugin that already takes advantage of this

4. bootstrap variables

note, that these will be ‘normal’ level attributes so they will be permanent.
In general it is better to use roles/enviornments instead of bootstrap variables since they get hard to keep track of.

knife bootstrap --json-attributes '{"foo": "bar"}'

Also, if using powershell, you may need to use the ‘tripple’ escape to have nested strings

 knife bootstrap --json-attributes '''{"foo": "bar"}'''

#5

Thank you so much!! Really appreciate the help….