I would like to add the staging environment like a subdomain, like staging.namesite.co.uk.
I tried but I receive this error:
Site `staging.namesite.co.uk` is not valid. Available sites to deploy:
namesite.co.uk
fatal: [178.62.42.53]: FAILED! => {"changed": false, "failed": true}
these are my settings in the /group_vars/ directory for production/staging
Read the error, it is telling you exactly what the problem is:
Site `staging.namesite.co.uk` is not valid. Available sites to deploy:
namesite.co.uk
fatal: [178.62.42.53]: FAILED! => {"changed": false, "failed": true}
Specifically, it is saying
Hey mattia, you’re trying to deploy a site called staging.namesite.co.uk but I don’t have any record of that site, so I can’t deploy it! Here is a list of the sites I do have a record of:
namesite.co.uk
This means that your Trellis config doesn’t have a site named staging.namesite.co.uk, which is a conclusion supported by the code you posted: None of your sites have the key staging.namesite.co.uk.
Specifically, your staging site uses the same key as your production site:
Changing the above to use the key staging.namesite.co.uk will likely fix your problem.
I feel like another important note on this issue is that the “site name” is just a handy name for deploying sites and has nothing to do with the environment to which you are deploying.
If your group_vars/staging/wordpress_sites.yml is written as you say…
The first argument (staging) tells the script what environment to deploy to, and the second argument (namesite.co.uk) tells it what site to deploy.
Trellis is designed with the idea that you’ll use the same site name regardless of the environment, because a staging site is still part of the same project as the production site.
So I recommend not changing wordpress_sites.yml and simply typing the deploy command differently instead.