Hey Byron,
I'm using Ansible with multiple environments daily and it's very easy
once you unlearn what Ansible documentation presents as a best
practice.
First, forget about /etc/ansible/ directory and its contents. Instead,
in your home directory create separate directories, each one for a
different "environment" - production, staging, testing, etc. For
example:
~/src/projects/example.com/production/
~/src/projects/example.com/staging/
Additionally create a separate directory for all of your playbooks
that will be applied to both environments:
~/src/projects/example.com/playbooks/
Now, cd into one of the project directories (let's say
~/src/projects/example.com/staging/) and assume that you work from
there. The same steps should be performed in the other project
directory.
Create ansible inventory and other required directories, for example:
ansible/inventory/hosts
ansible/inventory/group_vars/all/
ansible/inventory/group_vars/group/
ansible/inventory/host_vars/<hostname>/
ansible/roles/
ansible/playbooks/
In the project directory, create 'ansible.cfg' file with contents:
[defaults]
inventory = ansible/inventory
roles_path = ansible/roles/
You can add any variables from /etc/ansible/ansible.cfg that you want,
just make sure that it points to your local project directory instead
of the /etc/ansible/ directory. Put your playbooks and roles in
previously created directories. It's easier if you put them in a
shared common directory and symlink them to project directories.
Now, when you want to work in a staging environment, or production
environment, all you need to do is cd into it and ansible should
(using local ansible.cfg file) automatically use that environment. So
for example to run your main playbook, run:
ansible-playbook ansible/playbooks/site.yml -l host
And to switch to production environment, run:
cd ../production
These environments should be completely separate and should use
different hosts. You could try and combine different parts of the
inventory between them, but it might get tricky. Regardless, you
should use the same set of playbooks and roles in both environments to
be sure that staging environment reflects your production environment.
Only think that should be different is contents of the
'ansible/inventory/' directory, if needed.
Try it out a couple of times and I think that you will like it.
Cheers,
Maciej