Skip to content

Instantly share code, notes, and snippets.

@Aslan
Created May 22, 2013 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Aslan/5631854 to your computer and use it in GitHub Desktop.
Save Aslan/5631854 to your computer and use it in GitHub Desktop.
# provider
action :set do
chef_config = ""
if node[:ec2][:userdata]
chef_config = JSON.parse(node[:ec2][:userdata])
if chef_config.kind_of?(Hash)
chef_config = chef_config["attributes"]["run_list"]
if chef_config.kind_of?(Array)
chef_config = chef_config.first.split(/\[|\]/).last.gsub("_","-")
end
end
elsif node[:roles]
if node[:roles].kind_of?(Array)
chef_config = node[:roles].first
else
chef_config = node[:roles]
end
end
hostname = chef_config + "-" + node[:ec2][:instance_id].split("-").last
execute "set_hostname" do
command "hostname #{hostname}"
end
template "/etc/hosts" do
variables(:hostname_fqdn => "#{hostname}.mydomain.com", :hostname => hostname)
source "etc_hosts.erb"
mode "0664"
end
ohai "Ohai reload" do
action :reload
end
end
# recipe:
e = system_config_hostname "set my hostname" do
action :nothing
end
e.run_action(:set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment