03-10-2023 09:40 PM
I’m curious if anyone has created a better solution to something I have run up on. Despite days juggling different ideas and searching around I have not seen an example of ansible playbooks that does not explicitly match all inventory hosts in their ansible playbook to push configuration changes from a CI/CD pipeline. This may work for some but we have hundreds of devices. I feel like there is a better way to do this and as such my current solution is to type in the merge request title in Gitlab as a list of devices that are changing and this works great because I can then in my pipeline pass that var into the playbook call. However, due to the nature, if a user forgets that in the change control process, it breaks. Is anyone else doing something better or have any pointers? I’ve considered parsing the git log and finding configuration files that changed and looping through that but I also feel like there’s something easier I am just missing.
For extra context our current solution is:
Using GitLab create a merge request of changed configs, pass in the hosts changing in merge request title, in my pipeline call the push ansible playbook and pass in the merge request title as the hosts var.
Solved! Go to Solution.
03-24-2023 03:20 PM - edited 03-24-2023 03:23 PM
Here is the code I wrote that solved this for me.
https://github.com/ChadPunk/Ansible-Gitlab-List-of-changed-devices-for-pipeline
If you need any help don't hesitate to reach out.
03-13-2023 10:08 AM
03-12-2023 01:04 AM
In the past my devices were set by type (vendor, verion etc), location, edge, core etc.. all within the names. This made it easy to select devices when making changes. I think in your case youcan pass a list of changed hosts into a GitLab pipeline by using the pipeline variables feature. You can set the pipeline variables to a list of the hosts you want to target with your Ansible playbook. Then, in the pipeline configuration, you can reference the pipeline variables to pass the list into your Ansible playbook.
03-17-2023 11:11 AM
This is actually what I am already doing but in a unique way (which I am trying to get away from). Currently I use the merge title to compile a list of devices and then in the pipeline using the GitLab 'CI_COMMIT_TITLE' and pass that into the playbook. So if a user changes a bunch of devices they would in the title of the merge request specify the devices changing ie. "core1,core2,site-a,site-b". GitLab would then use that message and pass it into the playbook as a var. This does however create some challenges. If the user mistypes or forgets all together, it will fail. I have since posting the original question discovered a better way on my own that I will share with the community when I have the time to do a write up, that dynamically does this behind the scenes and works great.
03-24-2023 03:20 PM - edited 03-24-2023 03:23 PM
Here is the code I wrote that solved this for me.
https://github.com/ChadPunk/Ansible-Gitlab-List-of-changed-devices-for-pipeline
If you need any help don't hesitate to reach out.
04-08-2023 01:49 PM
I appreciate you taking the time to write that out as it may help others but I was already doing this but more of a manual way to create the list of changed devices (see one of my previous comments). I created a dynamic way to do this using the GitLab API to do this automatically and without user intervention. I accepted that as the solution.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide