Staging environment settings as subdomain

I set up and deployed the production correctly but I am having problems to set up a staging environment.

I am using gasmask to change my host file.

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

staging > wordpress-sites.yml

  namesite.co.uk:
    site_hosts:
      - canonical: staging.namesite.co.uk

staging > vault.yml

vault_wordpress_sites:
  namesite.co.uk

production > vault.yml

vault_wordpress_sites:
  namesite.co.uk

production > wordpress-sites.yml

 namesite.co.uk:
    site_hosts:
      - canonical: namesite.co.uk
        redirects:
          - www.namesite.co.uk

am I missing a step for the subdomain or there is something wrong in these settings?

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:

  1. 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.

2 Likes

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…

  namesite.co.uk:
    site_hosts:
      - canonical: staging.namesite.co.uk

Then to deploy to staging you can type…

$ deploy.sh staging namesite.co.uk

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.

2 Likes

Great, @MWDelaney thanks for the explanation, now it is more clear to me.