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.
Also see: What’s the ‘environment’ task in Rake?.