Using Ruby 2.0 on Amazon Opsworks

Using Ruby 2.0 on Amazon OpsWorks

OpsWorks now fully supports Ruby 2.0, in Layer settings you can specify the version of Rails, Bundler and Rubygems.

OpsWorks Screenshot

How to start rails console in AWS OpsWorks

Fix

  • Use root / su account
  • Delete Gemfile.lock
  • install rails and bundler gems
  • $ bundle install --binstubs
  • gem 'sprockets', '~>3.0'in Gemfile
  • bundle update sprockets
  • $ RAILS_ENV=production bundle exec rails console

Note: * Commit the new / modified files.

Set environment variables with AWS Opsworks

This can now be done directly from the AWS Console, on the application configuration, as per documentation : http://docs.aws.amazon.com/opsworks/latest/userguide/workingapps-creating.html#workingapps-creating-environment

Opsworks : Rails App Layer : specify Ruby minor version

Ah ha, I picked up tips from some old doco I think.

By reading the aws/opsworks code I corrected my custom json to this:

"ruby": {
"version": "2.1.2"
}

and it worked!

Actually, this is only partially a correct answer.

I have one stack that responded to this and downgraded correctly and another stack that would not downgrade my ruby version, it reports this on "update_dependencies" and continues to fail on deploy.

Userspace Ruby version is up-to-date (2.1) 

only my version when logged in is 2.1.5.

Many many re-deploys and update dependencies later eventually they all updated.

Change hostname in AWS OpsWorks (Chef)

I figured it out. You're suppose to override the default template in Chef that AWS provides.

Extending AWS OpsWorks Configuration Files Using Custom Templates

So in my cookbook, I made a file called:

opsworks_stack_state_sync/templates/default/hosts.erb

Add the file looks like this:

# This file was generated by OpsWorks
# any manual changes will be removed on the next update.

# Set the hostname with proper format, the rest are aliases.
127.0.0.1 localhost localhost.example.com
127.0.1.1 <%= node[:opsworks][:instance][:hostname] %>.example.com <%= node[:opsworks][:instance][:hostname] %>

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

# OpsWorks Layer State
<% seen = [] -%>
<% node[:opsworks][:layers].each do |layer_name, layer_config| -%>
<% layer_config[:instances].each do |instance_name, instance_config| -%>
<% if !seen.include?(instance_name) && instance_config[:private_ip] -%>
<%= Resolv.getaddress(instance_config[:private_ip]) %> <%= instance_name %>
<% if instance_config[:ip] %>
<%= Resolv.getaddress(instance_config[:ip]) %> <%= instance_name %>-ext
<% end %>
<% seen << instance_name %>
<% end -%>
<% end -%>
<% end -%>

And that will set your hostname to apple-pie.example.com.



Related Topics



Leave a reply



Submit