Hello,
We have ansible code that are in version control repository. This makes how to maintaining “ONE” inventory file difficult. If we need to create multiple repositories, for different purpose of Ansible playbook running, it breaks “ONE” inventory file assumption. In practice, does everyone maintain their inventory file in one single version control repository, or in multiple version control repositories? Would multiple inventory files in multiple version control repositories create inconsistency issue?
Thanks,
Hi
Hard to tell without knowing what and how things are deployed, and by what people/teams. If you provide that context we can give it a try.
Hi Dick,
So how do we construct inventory files depending on the factors of deployment process and people/teams, right? I once heard DevOps has people over process, process over automation wisdom, but I never understand what people means in DevOps. So we need first consider what teams/people are responsible first, then what is the process for those teams/people, right?
As people, we basically are divided into system people and development people. System people responsible for building, administering, operating, monitoring, incl, but not limited to computing resources, storage, network; while development people responsible for writing custom code. If the custom code depends on any 3rd party modules, system people typically responsible for installing/configuring/patching that 3rd party modules. Some times system people have to deal with testing in the case of changing one version from another version, like database.
The development team is using Gitlab as their versioning control system. Gitlab provides AutoDevOps, but we can’t use. Our custom code isn’t in those AutoDevOps areas. The infrastructure code is also versioning controlled in Gitlab. Gitlab has project repository. We try to keep infrastructure code in one repository. But it appears one repository is corresponding one pipeline. Per system perspective, all is infrastructure, until at the application level. So different applications may have different repository, and different set of infrastructure instances to serve them.
I don’t know how people handle inventory file version controlling like us. Are you willing to share some of your insights?
Thanks,
HI,
You are certainly correct that adding your host file to each repository is not a solution.
As I see it you have a few options:
-
Create an environment repository with your host file and your cfg file and anything else you might need and clone your playbook repositories underneath that repository. Not ideal
-
Clone your hosts file repository within your playbook repository. Also not ideal
-
Use something like git submodule or git subtree to do option2 in a more structured manner
https://www.atlassian.com/git/tutorials/git-subtree
-
have your hosts/inventory repository somewhere outside your repo and reference that host file when you call your playbook
`
root@f23399314267:/ansible_local/cisco_aci# ansible-playbook -i …/global_hosts test.yml
PLAY [ACI Configuration Snapshot] *************************************************************************************************
`
or
`
root@f23399314267:/ansible_local/cisco_aci# ansible-playbook -i …/master_inventory/global_hosts test.yml
PLAY [ACI Configuration Snapshot] *************************************************************************************************
`
- Look at other, more dynamic ways to include your hosts file. Ansible has options for a dynamic inventory file because your inventory will likely be dynamic. Not sure keeping it in git is the best long term action (but I do understand it).
In a situation like yours where I have different playbooks in different environments that act against a single inventory file I use option 4 and option 5.
Claudia