How do I stage a configuration change?

Hi, I’m new to ansible but liking what I see so far. I’m using it to configure a bunch of machines acting as routers across a region, and I like the model so far.

Now I’m trying to set up a couple of machines as a staging environment so I can check out configuration changes before I push them to production machines.

In http://docs.ansible.com/playbooks_best_practices.html a separate inventory file for stage and production is recommended.
OK, but how do I actually apply a different configuration to the staging machines from production? I see further down it’s recommended to keep the playbooks and inventory files in git. Am I supposed to branch the whole thing and use a test branch which gets applied to staging machines? Or is there an ansible feature to switch between staging and production?

I have a simple file copy which I want to do different on staging vs. production. I could set up a template and choose different content depending on whether we’re deploying to staging or production, but that seems the wrong way to do it. It’s really just a different version of the same file, and I want to choose one version for staging servers and another for production.

How do others do this?

Cheers,
Alex

I would not recommend using a seperate branch unless there are seperate versions of the product, branching is great for versions, not great for environments.

Differences in environment should be modelled by differences in group_variables where possible – and possibly in a slightly different top level playbook, all leveraging many common roles.

Then it’s just

ansible-playbook site.yml -i production

vs

ansible-playbook site.yml -i stage

Michael DeHaan <michael@ansible.com> napisał:

I would not recommend using a seperate branch unless there are seperate
versions of the product, branching is great for versions, not great for
environments.

What do you think about having a staging branch that's followed by a production one? Then production would have an easy to see "lag", and could even have custom hotfixes. I've seen this model work for web apps versioning, and I wonder if it's recommended for Ansible.

It would still use the standard mechanisms (separate inventories, group/host vars) for differences between those environments in configuration, but not for difference in time when the configuration was deployed.

I’m generally not a fan of keeping production/stage variance differed by branch.

The reason for this is merging is a “fun” exercise and then diff across branches is complicated.

I’d look towards branches as you do in software projects and use them for different versions of things, but think of prod vs stage as two different models, rather than branches.

So what is a “stage webserver” vs a “production webserver” is not really different from the question (to a degree) of how a stage webserver is different from a production webserver – they are both machines
built out of the same repo, using slightly different parameters.

–Michael