Drupal 7 Environment Dependency Management with the Master Module
The Master Module is a solution to the problem of ensuring that your site has the correct modules in each environment.
In a settings file, you specify a list of base modules which all environments use. You then specify for each environment which extra modules it needs.
At Deeson we have a very specific way of managing our settings.php file which can be seen here. This approach allows us to have a file at sites/all/conf/master.settings.inc which contains our master configuration which specifies which modules should be enabled on each environment. Our appraoch will also have defined a PHP constant of SETTINGS_ENVIRONMENT which will be either local, dev, test or prod depending on which environment the site is running on and use this to define the correct list of modules for the site.
Note that this is slightly different to how the documentation for Master module is described which uses its own definition of each environment as a scope. By using our standard SETTINGS_ENVIRONMENT constant we can define per environment settings for the Master module in the same was as we would do for any other module in our settings file.
A simple master.settings.inc is described below:
<?php /** * @file * Master configuration file for all environments. */ $conf['master_current_scope'] = 'base'; $conf['master_version'] = 2; $conf['master_allow_base_scope'] = TRUE; $conf['master_modules'] = array( 'base' => array( 'admin_menu', 'admin_menu_toolbar', 'block', 'coffee', 'ctools', 'field', 'field_sql_storage', 'file', // ... and other modules which should be in all environments. ), ); if (SETTINGS_ENVIRONMENT === 'local') { $conf['master_modules']['base'][] = 'devel'; $conf['master_modules']['base'][] = 'field_ui'; $conf['master_modules']['base'][] = 'views_ui'; // ... and other modules just for local. } if (SETTINGS_ENVIRONMENT === 'dev') { $conf['master_modules']['base'][] = 'styleguide'; // ... and other modules just for the dev environment. } if (SETTINGS_ENVIRONMENT === 'test') { $conf['master_modules']['base'][] = 'shield'; // ... and other modules just for the test environment. } if (SETTINGS_ENVIRONMENT === 'prod') { $conf['master_modules']['base'][] = 'acquia_spi'; // ... and other modules just for the production environment. }
With the Master module settings in place, you can now use the following drush commands:
drush master-status
This drush master-status command lists all the modules on your site in the following sections:
Required modules: Modules which are presently not defined in your master settings file for the current environment but would be enabled because there are dependencies on them because of other modules which are required in your current environment. They probably should be defined in your settings file for this environment.
Missing modules: These are modules which should be enabled in your current environment but are not.
Redundant modules: These are modules which are enabled in your current environment but should not be.
Uninstall modules: These are modules which are presently disabled and not required in your current environment and should be uninstalled.
drush master-execute
The drush master-execute command will enable required and missing modules, and disable and uninstall redundant modules. It will prompt you before taking action if used without the -y option.
If you are using some form of continuous integration then this can be really helpful since you can use it to ensure all modules which should be enabled are in a given environment. When you add a new module to the site, you just have to put it into the right environment section of your master settings file and the Master module will take care of the rest.