How do I find the role id from role name?
Knowing the machine name of the role, it is enough to use user_role_load_by_name().

if ($role = user_role_load_by_name('Role Name')) {
  // The role ID is in $role-&gt;rid.
}


If the Role might not exist...

$role = user_role_load_by_name('Role Name');

$role_id = $role ? $role-&gt;rid : NULL;