Roles and Permission creation programatically inside module I am trying to create drupal 8 roles and permissions programatically. My current approach is to have a module that when install it will generate those set of roles and permissions defined by the  module. It would be more like a background Module, where no form is needed or anything. My problem lies that I really don't know where to start the the roles creations since no form is needed, I mean should I create them inside a hook?, if so which hook?, any other place?

I really don't know if this is the best approach, still a newby on drupal 8. Any suggestions will be greatly appreciate it.

Thanks in advance
Create the roles on your development site and grab the configuration for them and place them in:

&lt;modulename&gt;/config/install 


When the module is installed it will import that configuration. hook_install is deprecated for installing configuration with a module.

Remove any uuid information from the export as it won't be applicable in most sites.

If you are unaware how to export/import configuration in drupal 8, you should read:
D8 Configuration Management

edit: Just as an aside fact, you can in theory write your own config.yml files however until you are very familiar it's easier to just create the role, and export it.