Idiomatic way of adding switches to Ansible directives from command-line?

Hello folks,

I set up my deployment flow in such a way that Ansible clones a git repo locally (generally named “myrepo-deploy” and never modified by hand), cleans and syncs it as master, builds the contents and deploys them to either dev, production or pre-production depending on which hosts file I choose for ansible-playbook.

The challenge is that sometimes I need to deploy from a modified copy of the above repo where development work is happening. e.g. instead of using clean myrepo-deploy against preproduction, I’d like to use myrepo (with some uncommitted modifications in it) against preproduction just for testing purposes.

So I’d love to be able to be able to pass a switch to ansible-playbooks and say “use the development version of the repo just this one time”.

  • I know there’s an option with when: and using environment variables
  • I know I could also create a separate hosts file that’s something like “preprod-dev”, but now I have to make one of these for each of my host files and it adds an extra burden of variable maintenance in 2x files.

Is there perhaps a better practice that you could recommend for this kind of situation?

Thank you in advance!

Right now the git module doesn’t really like it when you change from one repo to another.

You might solve this by removing the directory prior to calling the git module, which obviously has some side effects, but this seems to ring with a “don’t do that” kind of answer, which you might not like.

If you are testing your branch, it seems you should deploy that to a test VM, and production should always go off the same repo, as a matter of policy…

Not saying a repo switch on the directory should not be possible, but it’s a bit of a niche thing, and even git doesn’t really support “replace this repo with that one in the same place”.