# Production server provision configures Staging envs if hosts are the same - Bug or Intention?

**URL:** https://discourse.roots.io/t/production-server-provision-configures-staging-envs-if-hosts-are-the-same-bug-or-intention/6090
**Category:** trellis
**Created:** 2016-03-02T16:09:21Z
**Posts:** 10
**Showing post:** 2 of 10

## Post 2 by @fullyint — 2016-03-02T18:09:04Z

@craigpearson Thank you for reporting this! It is definitely not the intention that Trellis will load staging information when you specify `env=production`. It’s an ‘unexpected behavior’ resulting from an unexpected usage of including your host `195.50.84.246` in multiple environment groups (in `[staging]` and `[production]` simultaneously). Ansible sees multiple groups for the host and picks one; not always the one you want.

Your unexpected usage is to have both staging and production on the same server. I realize there may be some cases/arguments for it, but generally the recommendation is to put them on separate servers. The $5/month DigitalOcean droplets make it feasible. I like having the freedom to mess with a site’s staging server without constraints. I wouldn’t have this freedom and full ability to test things if the server were serving the production site. I couldn’t reprovision, reboot, rebuild as much as I like to do.

Thinking about Ansible internals, I’m not sure we can just make this issue silently fix itself in the background. However, I’m pretty sure we can detect that a host is in multiple environment groups, halt the playbook, and present a message suggesting a couple options. You can choose one of these options.

**Option 1 - Adjust host files, use same commands**  
I’d recommend this option. Adjust your hosts files like this:

```
# hosts/staging
my_staging_hostname ansible_host=195.50.84.246

[staging]
my_staging_hostname

[web]
my_staging_hostname
```

( **Edit** in file below, suggested by @dutchmichael [here](https://discourse.roots.io/t/production-server-provision-configures-staging-envs-if-hosts-are-the-same-bug-or-intention/6090/10): `[staging]` should be `[production]`)

```
# hosts/production
my_production_hostname ansible_host=195.50.84.246

[production]
my_production_hostname

[web]
my_production_hostname
```

You can edit `my_staging_hostname` and `my_production_hostname` to be whatever you want, so long as it is not an IP and the name is consistent across its three appearances in any given host file. This resolves the problem by assigning a hostname that differs between the `[staging]` group and the `[production]` group, even though the underlying `ansible_host` parameter is the same.

Then you can run `ansible-playbook` commands like normal.

**Option 2 - Adjust your commands**  
As you know, the [default inventory](https://github.com/roots/trellis/blob/2a1954b18b3d274d8a015a0f3b4f7ad7a27cfbb6/ansible.cfg#L4) Trellis loads is the entire `hosts` directory. You can override this and make it load just the `hosts/production` file by adding the `-i` option (inventory file) to your command:

```
ansible-playbook server.yml -i hosts/production -e env=production
```

or

```
ansible-playbook server.yml -i hosts/staging -e env=staging
```

---

_[View the full topic](https://discourse.roots.io/t/production-server-provision-configures-staging-envs-if-hosts-are-the-same-bug-or-intention/6090)._
