Created
July 26, 2011 21:12
-
-
Save Aslan/1108055 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
# The recipe that calls the method | |
Chef::Log.info elb_name(node) | |
ruby_block "register_with_elb" do | |
block do | |
require 'AWS' | |
if associate_elastic_ip # Make sure it has a white listed elastic IP | |
unless production_primary_backendapp? # Production Primary backend app does not need to be on the load balancer any more. | |
ec2 = AWS::ELB::Base.new(:access_key_id => "yyyyyy", :secret_access_key => "xxxx") | |
ec2.register_instances_with_load_balancer(:load_balancer_name => "#{elb_name(node)}", :instances => ["#{node[:ec2][:instance_id]}"] ) | |
end | |
end | |
end | |
end |
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
#other methods that work | |
#.. | |
def production_primary_backendapp? | |
roles = node.run_list.roles.first rescue nil | |
roles == "primary_backend_app_production" | |
end |
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
def associate_elastic_ip | |
if has_elastic_ip? | |
Chef::Log.info "Elastic ip is already associated." | |
return true | |
elsif free_ip = elastic_ips | |
Chef::Log.info "Associating elastic ip #{free_ip} to this node" | |
ec2 = AWS::EC2::Base.new(:access_key_id => "xxxxx", :secret_access_key => "yyyy") | |
ec2.associate_address(:public_ip => free_ip, :instance_id => @node[:ec2][:instance_id]) | |
return true | |
else | |
Chef::Log.info "There are no more available elastic ips" | |
return false | |
end | |
end |
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
2011-07-26_20:43:30.71009 [Tue, 26 Jul 2011 13:43:30 -0700] ERROR: ruby_block[register_with_elb] (/var/chef/cache/cookbooks/configure-site/recipes/backend.rb:145:in `from_file') had an error: | |
2011-07-26_20:43:30.71010 undefined method `production_primary_backendapp?' for Chef::Resource::RubyBlock | |
2011-07-26_20:43:30.71012 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource.rb:144:in `method_missing' | |
2011-07-26_20:43:30.71013 /var/chef/cache/cookbooks/configure-site/recipes/backend.rb:149:in `from_file' | |
2011-07-26_20:43:30.71014 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/provider/ruby_block.rb:28:in `call' | |
2011-07-26_20:43:30.71015 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/provider/ruby_block.rb:28:in `action_create' | |
2011-07-26_20:43:30.71016 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource.rb:395:in `send' | |
2011-07-26_20:43:30.71017 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource.rb:395:in `run_action' | |
2011-07-26_20:43:30.71018 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:53:in `run_action' | |
2011-07-26_20:43:30.71020 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:89:in `converge' | |
2011-07-26_20:43:30.71021 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:89:in `each' | |
2011-07-26_20:43:30.71022 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:89:in `converge' | |
2011-07-26_20:43:30.71024 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection.rb:94:in `execute_each_resource' | |
2011-07-26_20:43:30.71025 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call' | |
2011-07-26_20:43:30.71026 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block' | |
2011-07-26_20:43:30.71027 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:85:in `step' | |
2011-07-26_20:43:30.71028 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate' | |
2011-07-26_20:43:30.71029 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index' | |
2011-07-26_20:43:30.71030 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection.rb:92:in `execute_each_resource' | |
2011-07-26_20:43:30.71032 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:84:in `converge' | |
2011-07-26_20:43:30.71034 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/client.rb:268:in `converge' | |
2011-07-26_20:43:30.71035 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/client.rb:171:in `run' | |
2011-07-26_20:43:30.71036 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/application/client.rb:222:in `run_application' | |
2011-07-26_20:43:30.71037 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/application/client.rb:212:in `loop' | |
2011-07-26_20:43:30.71038 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/application/client.rb:212:in `run_application' | |
2011-07-26_20:43:30.71040 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/application.rb:62:in `run' | |
2011-07-26_20:43:30.71041 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/chef-client:26 | |
2011-07-26_20:43:30.71042 /opt/ruby-enterprise/bin/chef-client:19:in `load' | |
2011-07-26_20:43:30.71043 /opt/ruby-enterprise/bin/chef-client:19 | |
2011-07-26_20:43:30.71043 [Tue, 26 Jul 2011 13:43:30 -0700] ERROR: Running exception handlers | |
2011-07-26_20:43:30.71044 [Tue, 26 Jul 2011 13:43:30 -0700] ERROR: Exception handlers complete | |
2011-07-26_20:43:30.71045 [Tue, 26 Jul 2011 13:43:30 -0700] ERROR: NoMethodError:undefined method `production_primary_backendapp?' for Chef::Resource::RubyBlock | |
2011-07-26_20:43:30.71049 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource.rb:144:in `method_missing' | |
2011-07-26_20:43:30.71050 /var/chef/cache/cookbooks/configure-site/recipes/backend.rb:149:in `from_file' | |
2011-07-26_20:43:30.71051 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/provider/ruby_block.rb:28:in `call' | |
2011-07-26_20:43:30.71052 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/provider/ruby_block.rb:28:in `action_create' | |
2011-07-26_20:43:30.71053 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource.rb:395:in `send' | |
2011-07-26_20:43:30.71054 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource.rb:395:in `run_action' | |
2011-07-26_20:43:30.71055 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:53:in `run_action' | |
2011-07-26_20:43:30.71056 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:89:in `converge' | |
2011-07-26_20:43:30.71057 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:89:in `each' | |
2011-07-26_20:43:30.71058 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/runner.rb:89:in `converge' | |
2011-07-26_20:43:30.71061 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection.rb:94:in `execute_each_resource' | |
2011-07-26_20:43:30.71062 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call' | |
2011-07-26_20:43:30.71063 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block' | |
2011-07-26_20:43:30.71064 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:85:in `step' | |
2011-07-26_20:43:30.71065 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate' | |
2011-07-26_20:43:30.71066 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index' | |
2011-07-26_20:43:30.71067 /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/chef-0.9.14/bin/../lib/chef/resource_collection.rb:92:in `execute_each_resource' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment