Created
March 27, 2012 23:47
-
-
Save miah/2221571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include_recipes | |
| include_recipe "route53" | |
| # Translate the role into a shortname. | |
| role_trans = { | |
| "memcached" => "mc", | |
| "wordpress" => "wp", | |
| "rails" => "rails", | |
| "lb" => "lb", | |
| "monitoring" => "mon", | |
| "chef-server" => "ops", | |
| "ci" => "ci", | |
| "openvpn" => "vpn", | |
| "rundeck" => "deploy", | |
| "log" => "log", | |
| "sensu" => "sensu", | |
| "database" => "db" | |
| } | |
| #determine system roles | |
| $hnroles = Array.new | |
| node[:roles].each do |i| | |
| if role_trans.include?(i) then | |
| $hnroles << role_trans.fetch(i) | |
| end | |
| end | |
| #set host_fqdn to ec2 instance id - roles . ctothex.com | |
| shortname = node['ec2']['instance_id'] + "-" + $hnroles.sort.join | |
| domain = "myawesome.com" | |
| host_fqdn = "#{shortname}.#{domain}" | |
| #Find monitor nodes | |
| mnodes = Hash.new | |
| search(:node, "role:monitoring AND chef_environment:#{node.chef_environment}") do |n| | |
| mnodes[n.fqdn] = { 'address' => n.ipaddress, | |
| 'fqdn' => n.fqdn, | |
| 'hostname' => n.hostname } | |
| end | |
| file "etc_hostname" do | |
| path "/etc/hostname" | |
| mode 0444 | |
| owner "root" | |
| group "root" | |
| content "#{host_fqdn}\n" | |
| notifies :run, "execute[hostname]", :immediately | |
| end | |
| template "etc_hosts" do | |
| path "/etc/hosts" | |
| source "hosts.erb" | |
| owner "root" | |
| group "root" | |
| mode 0444 | |
| variables( | |
| :fqdn => host_fqdn, | |
| :shortname => shortname, | |
| :mnodes => mnodes | |
| ) | |
| end | |
| template "etc_resolv" do | |
| path "/etc/resolv.conf" | |
| source "resolv.conf.erb" | |
| owner "root" | |
| group "root" | |
| mode 0444 | |
| variables( | |
| :domain => domain | |
| ) | |
| end | |
| execute "hostname" do | |
| command "hostname -F /etc/hostname" | |
| action :nothing | |
| end | |
| route53_record "create a record" do | |
| name "#{host_fqdn}" | |
| value node['ec2']['public_hostname'] | |
| type "CNAME" | |
| ttl 300 | |
| zone_id YOURAWSR53ZONEID | |
| aws_access_key_id REFERNCEYOURAWSID | |
| aws_secret_access_key REFERENCEYOURAWSKEY | |
| action :create | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment