Creating roles programmatically
From MoodleDocs
You may find that the default roles do not answer the needs of your plugin. In that case, you want to create a role programmatically.
Setup
The first step is to create an install.php file in the db folder of your plugin.
''moodle root''/mod/myplugin/db/install.php