roots / trellis-cli

A CLI to manage Trellis projects
https://roots.io/trellis/
MIT License
167 stars 25 forks source link

Trellis CLI deploy flag suggestion #208

Closed jt-adwisemedia closed 2 years ago

jt-adwisemedia commented 2 years ago

Summary

Add support for the --limit flag for the trellis deploy <environment> command, currently we have to write the entire ansible-playbook deploy.yml -e env=production -e site=yoursite.tld --limit=kinsta_production, would be nice if you could just write trellis deploy production --limit=kinsta_production.

Motivation

Nice quality of life change, convenience.

swalkinshaw commented 2 years ago

Probably makes sense to support natively. In the meantime, I think you could use extra vars:

trellis deploy --extra-vars ansible_limit=kinsta_production production
swalkinshaw commented 2 years ago

@jt-adwisemedia I assume you're using the limit option because of this guide? https://kinsta.com/blog/bedrock-trellis/

In most cases, limit shouldn't be needed at all because there's only one host per environment. Ie: one staging server, one production server, etc.

We'll try and get that guide updated because limit seems redundant. This means you also don't need that option when using the CLI. You can verify this by just running trellis deploy production and making sure it does the same thing as with --limit.

If there's a difference, feel free to re-open this issue.

dalepgrant commented 2 years ago

@swalkinshaw I've come here looking for exactly this. Example of a use case here in Roots Discourse.

We have our Trellis structured as follows:

trellis/
├── group_vars/         
    └── production/
        ├── main.yml
        └── vault.yml
    └── staging/
└── host_vars
    └── server1/
        └── wordpress_sites.yml
    └── server2/
    └── staging1/
    └── staging2/

Our deploy then looks like this with the old deploy.sh script:

./bin/deploy.sh production domain.example --limit=server1

Not strictly related to this issue, but if I try to run your suggestion while provisioning, trellis-cli gives an error

trellis provision --extra-vars ansible_limit=server1 production
Error: production is not a valid environment, valid options are [development]
swalkinshaw commented 2 years ago

That should work... can you try it with quotes?

trellis provision --extra-vars "ansible_limit=server1" production
swalkinshaw commented 2 years ago

Wait sorry I misread that error message. It's handling the command correctly but it's only detecting the development environment for some reason?

Do you not have a wordpress_sites.yml file under production? That's how it detects environments

dalepgrant commented 2 years ago

No, the wordpress_sites.yml files are under the host_vars folders, one per server so we can choose which site(s) sit where.

swalkinshaw commented 2 years ago

Opened a new issue for that: https://github.com/roots/trellis-cli/issues/278