Setting host name with chef


#1

I’m trying to set the hostname with chef. I’m using the hostname cookbook.
Everything looks to be configured fine. However, even though the hostname
has been set correctly, a log statement shows the hostname is still the
automatic EC2 assigned one. Running ohai after the chef-client run is
complete also shows the hostname to be the automatic EC2 one. Again, the
configuration of the files are correct, and a hostname -f shows the correct
value. Running chef a second time, the log statement shows the correct
value. Obviously the results of setting the hostname aren’t available until
the next run. How can I fix this?

Doug.


#2

I think that is just the way how chef works, when it comes to gathering attributes. So the before every chef client run, it gathers the Ohio details from the node and the attributes from the cookbooks. This happens on every run, hence the right things or should I say the new hostname shows up in the second run.


#3

Wouldn’t reloading ohai work for this use case?

ohai 'reload' do
  action :reload
end

#4

David,

It didn’t help. Tried that. So, at this point, I can’t test our main java
application with test kitchen on ec2. Kitchen vagrant lets me set a
hostname, kitchen ec2 does not.

Doug.


#5

Is there not a delay between a hostname change and the update of ec2 metadatas ? (just a guess)


#6

This is with test kitchen, i.e. chef-solo, so does that apply?


#7

I ran into some issues using the hostname cookbook & EC2 as well: https://github.com/3ofcoins/chef-cookbook-hostname/issues/30

I ended up switching to the system cookbook: https://github.com/xhost-cookbooks/system & using lazy evaluation of node[‘fqdn’] in my recipes, as noted in the readme for the system cookbook. Maybe that can help you?


#8

Thanks.

Well, I tried the system cookbook, and got:

Starting Chef Client, version 11.12.4
       Compiling Cookbooks...
       Converging 1 resources
       Recipe: slice-hostname::default
         * system_hostname[starbug.reddwarf.space] action set

 ================================================================================
       Error executing action `set` on resource
'system_hostname[starbug.reddwarf.space]'

 ================================================================================

       NoMethodError

#9

Oh look… the mailing list is still truncating my posts… sigh.


#10

Try posting it to github as a gist instead and then paste the link