Skip to content

Switch ansible inventory file accordingly to current git branch.

License

Notifications You must be signed in to change notification settings

selivan/ansible-inventory-from-git-branch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ansible best practices recommend to have separate inventory files for production and testing environments. You may also keep your ansible files in git and have separate branches for environments. In such setup it's easy to confuse current branch and apply testing changes to production. It's more convinient and error-prone to automatically switch inventory according to currenty used git branch: if you checkout branch "prod" or named like "*.prod" - hosts.prod inventory file is used; otherwise hosts.test is used.

How it works: local ansible.cfg references to hosts inventory file, which is symlink to actual inventory for current branch. hosts is added to .gitignore to prevent merge conflicts between branches. Git hook is used to change hosts symlink each time user switches to other branch.

P.S. If this code is useful for you - don't forget to put a star on it's github repo.

About

Switch ansible inventory file accordingly to current git branch.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages