I don't seem to be able to get the administrator role id in 2.2 the way I used to in 1.9.
What I used to do was this:
$adminroles=get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $context);
$adminrole = array_pop($adminroles);
Then $adminrole->id had the role object id and I could use it in role_assign.
I know that role_assign has changed, and I am using
$retval = role_assign($adminrole->id, $userid, $context->id);
but the $adminrole->id is null.
Is there some easy fix, some proper Moodle 2-way of doing this?