roots / trellis-cli

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

Accommodating non-standard setups where wordpress_sites live outside of group_vars #278

Open swalkinshaw opened 2 years ago

swalkinshaw commented 2 years ago

trellis-cli is primarily designed around environments which are really inventory/host groups in Ansible. This is the standard setup where wordpress_sites.yml is defined in each environment group var folder.

Because of this, the CLI detects environments by a glob group_vars/*/wordpress_sites.yml and parses them to be "site aware". Obviously this means it won't support any other kind of setups. Below is an example where the sites are defined per host (not group) which breaks these assumptions.

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]

Originally posted by @dalepgrant in https://github.com/roots/trellis-cli/issues/208#issuecomment-1073518956

swalkinshaw commented 2 years ago

@dalepgrant forgot to ask, but with your setup you have no distinction between environments right? If so, you can just use development:

trellis provision --extra-vars ansible_limit=server1 development

The environment shouldn't really matter here... you just need one that exists to satisfy the requirements. Or, just dump a basic wordpress_sites.yml file in group_vars/production if you really need the production env for some reason.

Considering how rare this use case is, and how it's non-standard, it's unlikely trellis-cli will be able to support it properly.

dalepgrant commented 2 years ago

Huurrrm yeah we do have a distinction in that group_vars/[env]/* files are different. It's easier to maintain one production vault than multiple host vaults and keeps the difference from stock Trellis to a minimum, for example. Wouldn't setting the env as development for all servers mess up things like mail? I can confirm, for example, we don't have MailHog set up on anything other than development.

Over the years I've seen a few people asking for Trellis w/ multiple site setups, I'm sure we're not the only ones though most of the discussions about it in discourse go back a few years. I'll concede we're in the minority 😅 but the chap in #208 is also potentially in that minority.

For now (and for anyone else looking) the standard provision/deploy scripts work, they're just verbose e.g. Provision:

ansible-playbook server.yml -e env=staging --limit=[server]

Deploy, if you no longer have the bin scripts removed in #1352

ansible-playbook deploy.yml -e env=staging -e site=example.domain --limit=[server]

Thanks for looking nonetheless 🙏