mozilla / identity-ops

Tools and Chef cookbooks used by Mozilla Services Operations to provision and manage Persona
Other
24 stars 12 forks source link

persona-common::hostname fails to install ec2 hint and use resulting ohai attributes to form the hostname in a single run #109

Closed gene1wood closed 11 years ago

gene1wood commented 11 years ago

Though I wrote this to work in one run something is wrong. The hints get loaded but it looks like the ohai attributes don't get reloaded

Recipe: persona-common::hostname
  * directory[/etc/chef/ohai/hints] action create
    - create new directory /etc/chef/ohai/hints
    - change mode from '' to '0755'
    - change owner from '' to 'root'
    - change group from '' to 'root'

  * file[/etc/chef/ohai/hints/ec2.json] action create
    - create new file /etc/chef/ohai/hints/ec2.json
        (no diff)
================================================================================
Recipe Compile Error in /root/identity-ops/chef/cookbooks/persona-proxy/recipes/default.rb
================================================================================

NoMethodError
-------------
undefined method `[]' for nil:NilClass

Cookbook Trace:
---------------
  /root/identity-ops/chef/cookbooks/persona-common/recipes/hostname.rb:42:in `from_file'
  /root/identity-ops/chef/cookbooks/persona-common/recipes/default.rb:17:in `from_file'
  /root/identity-ops/chef/cookbooks/persona-proxy/recipes/default.rb:10:in `from_file'

Relevant File Content:
----------------------
/root/identity-ops/chef/cookbooks/persona-common/recipes/hostname.rb:

 35:          group "root"
 36:          mode 0644
 37:        end
 38:  res.run_action(:create)
 39:  reload_ohai ||= res.updated?
 40:  
 41:  # Note max hostname length : 64
 42>> short_hostname=node[:ec2][:instance_id] ? node[:ec2][:instance_id] : "ip-#{node[:ipaddress].tr('.','-')}"
 43:  new_hostname=short_hostname + 
 44:               (node[:tier] ? ".#{node[:tier]}" : "") + 
 45:               (node[:stack][:name] ? ".#{node[:stack][:name]}" : "") +  
 46:               (node[:stack][:type] ? ".#{node[:stack][:type]}" : "") +
 47:               (node[:aws_region] ? ".#{node[:aws_region]}" : "") +
 48:               ".allizomaws.com"
 49:  
 50:  res = template "/etc/hosts" do
 51:          source "etc/hosts.erb"