Rails: Why am I getting uninitialized Constant for a rake task, Rails 4.1.8
I'm not sure why either works, but if this is rails and those are rails models, your tasks should depend on the environment:
task :get_roles => [ :environment ] do
By depending on the :environment task, it first loads rails.
see also:
What's the 'environment' task in Rake?
You can also run rake task as
bundle exec rake environment xaaron:get_role
this will load Rails environment first.