We have a large set of Drupal instances, and we use Drush alias groups to group them logically. For example, we have a group "dev" for all sites "in development", and, for example, another called "7_36" for all on Drupal core 7.36.

I can currently run commands against all sites in a single group (drush @dev status), but is it possible to run a command against all sites which are in both groups? For example, I'd like to run a command against all sites found both in @dev and in @7_36.

Is this possible?


You can create a new alias group that is the combination of the two (by hand):

$aliases['newCombinedGroup'] = array(
  'site-list' => array(
    // Dev group 1 sites
    // 7_36 group 2 sites

This is discussed in this other thread: How to use Drush's concurrent execution capability?

Another option as pointed out by the maintainer of Drush here: https://drupal.stackexchange.com/a/134472/3279

is to compose your alias group site names for example from a PHP array of site names, then build your alias entries programmatically by looping through these site names and filling out the contents of the drush alias itself.

So something like:

// This is untested example code.
$sites_in_dev = array('site-dev-1', 'site-dev-2');
$sites_in_736 = array('site-1', 'site-2');

$aliases['newCombinedGroup'] = array(
  'site-list' => $sites_in_dev + $sites_in_736;
$aliases['@dev'] = array('site-list' => $sites_in_dev);
$aliases['@7_36'] = array('site-list' => $sites_in_736);

foreach ($sites_in_dev as $sitename) {
  if ($sitename == 'site-dev-1') {
    $aliases['Dev1'] = array( /* ... */ );
  if ($sitename == 'site-dev-1') {
    $aliases['Dev2'] = array( /* ... */ );

foreach ($sites_in_736 as $site) {
  // ... etc ...

.... You get the idea. Also I would refrain from using @7_36 as an alias name. In general PHP variables shouldn't start with numbers -- and while an alias isn't a php variable persay you're playing with fire by giving it a name that would be an invalid php variable name; when evaluated now and in future versions of Drush ... who knows how that will behave.

  • Thanks for the idea. This was helpful to me, as a newbie in drupal. However, seems that as of my current drush version (8.1.10), your first example should have been written as follows: $aliases['newCombinedGroup'] = array( 'site-list' => array( // Dev group 1 sites '@site1', '@site2', '@site3', // 7_36 group 2 sites '@site6', '@site7', '@site8', ), ); – icasimpan Sep 7 '17 at 20:29
  • @icasimpan yes, mostly likely your recommendation is correct. My post was from 2015, and Drush receives regular updates and so it's conventions change slightly over time. – tenken Sep 7 '17 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.