deployer icon indicating copy to clipboard operation
deployer copied to clipboard

Cannot select multiple selectors/labels

Open JasperAlgra opened this issue 3 years ago • 3 comments

Hi, I'm trying to refactor our use of deployer 6 to 7 and I'm running into an issue:

I have multiple stages e.g:

  • lab
  • staging
  • production

and multiple roles:

  • appserver
  • worker

I would like to run some commands only on a combination of both; e.g. my lab-appservers or production-workers.

Maybe I'm missingin something but right now I have this in my deployer config:

// Lab
host('app[01:04].lab.kantoor.eztrack.nl')
    ->set('labels', ['stage' => 'lab', 'roles' => 'appservers']);

// Staging
host('vmapp01.servers.kantoor.eztrack.nl')
    ->set('labels', ['stage' => 'staging', 'roles' => 'appservers']);

If I run only on a role OR a stage it works:

jasper@ET-DSK-JASPER:/repos/europetrack$ make deployer COMMAND_ARGS="run 'uptime -p' stage=lab"
[app01.lab.kantoor.eztrack.nl] up 9 weeks, 6 days, 2 hours, 49 minutes
[app02.lab.kantoor.eztrack.nl] up 9 weeks, 6 days, 2 hours, 55 minutes
[app03.lab.kantoor.eztrack.nl] up 9 weeks, 6 days, 2 hours, 59 minutes
[app04.lab.kantoor.eztrack.nl] up 9 weeks, 5 days, 20 hours, 53 minutes
jasper@ET-DSK-JASPER:/repos/europetrack$ make deployer COMMAND_ARGS="run 'uptime -p' stage=staging"
[vmapp01.servers.kantoor.eztrack.nl] up 17 weeks, 3 days, 21 hours, 16 minutes

but a combination of both returns anything matching (so all hosts from both stages in this case)

jasper@ET-DSK-JASPER:/repos/europetrack$ make deployer COMMAND_ARGS="run 'uptime -p' stage=staging roles=appservers"
[app01.lab.kantoor.eztrack.nl] up 9 weeks, 6 days, 2 hours, 51 minutes
[app02.lab.kantoor.eztrack.nl] up 9 weeks, 6 days, 2 hours, 57 minutes
[app03.lab.kantoor.eztrack.nl] up 9 weeks, 6 days, 3 hours, 1 minute
[app04.lab.kantoor.eztrack.nl] up 9 weeks, 5 days, 20 hours, 55 minutes
[vmapp01.servers.kantoor.eztrack.nl] up 17 weeks, 3 days, 21 hours, 17 minutes

Adding an "AND" to the selector fails selecting any host:

jasper@ET-DSK-JASPER:/repos/europetrack$ make deployer COMMAND_ARGS="run 'uptime -p' 'stage=staging AND roles=appservers'"

In SelectCommand.php line 84:

  No host selected. Please, check your selector:

      stage=staging AND roles=appservers

I cannot run xdebug easily on the deployer because I run through docker. As the docs speak about roles AND stages I assume this should work in some way. Maybe somebody could point me in the right direction? It would be much appreciated!

JasperAlgra avatar May 10 '22 13:05 JasperAlgra

Try this:

'stage=staging&roles=appservers'

antonmedv avatar May 10 '22 14:05 antonmedv

Great, that works! Thanks a lot. :) I'll try to setup a MR for the docs when I have some time. Probably helpful for others as well.

JasperAlgra avatar May 10 '22 14:05 JasperAlgra

I've written a small update for the docs. Not sure if I need to run the doc gen function.

https://github.com/deployphp/deployer/pull/3133

JasperAlgra avatar May 16 '22 12:05 JasperAlgra