So I am thinking about applying some new automation to my home setup in order to better automate things. This is mostly just for fun but I think it will also make it easier to quickly make changes.
I have been playing with Ansible pull and I like how it can pull from a git repo. Ideally I would want to have all my configurations in this repo. The idea is that I could make changes to the repo and everything then gets pulled down and applied.
I know I can't (and shouldn't) run Ansible pull in OpenWRT for many reasons but it should be possible to run a VM/container that just runs a Ansible pull that connects to OpenWRT.
Does anyone have a setup similar to this? If so how is it?
Afaik there are a bunch of people using ansible in various kind to admin their OpenWrt installations. Ne it actual AP or router or VPN VM.
Depends on how many voodoo you do I most of the time end up with simple templates or just file files which got applied to a d then either a service restart or full reboot...
If you are still looking for an Ansible-based configuration, I am happy to share that the Ansible community (personified in yours truly) has just started to release a collection named community.openwrt. The collection is already available in Ansible Galaxy, but it is still in a very crude state - it is lacking lots of documentation, and not everything is properly tested yet, so not for the faint at heart.
By the way, we are using the x86_64 docker images (e.g. openwrt/rootfs:x86_64-24.10.4) to run the (few existing) tests.
That being said, the code in there is mostly based on the code from the Ansible role gekmihesg.openwrt, and as that one before it, needs no Python to run. My home router config has been automated using that role since 2021, and while making the collection I used myself as lab rat for it - it is working smoothly - I still need to reset the router one day and configure it from scratch, for the sake of testing, but the idea of cutting off the wifi during the holidays (summer down here in New Zealand) is likely going to land me in the dog house.
My plan is to get a version 1.0.0 out by January (or even earlier if time allows), so watch this space.
This is awesome! Thanks for sharing! I also happen to have something similar for my home router I have upgraded it yesterday to 24.10.5 and everything went mostly smooth (I was testing some changes so I spent a lot of time going back and forth testing, but the end result was... magic )
Just one thing to keep in mind: until community.openwrt reaches version 1.0.0 we are bound to make breaking changes without much notice. Taking a quick look at your code I spotted one already: we renamed the community.openwrt.setuprole to community.openwrt.init, to disambiguate from the community.openwrt.setupmodule - and that was published in release 0.3.0, a couple of days ago. Your code is still using the old name.
Until 1.0.0 our focus is to get a solid base in the collection, writing tests, organizing things, improving the basic machinery of the colelction - Ansible never planned for shell script modules, but here we are . As soon as we reach that milestone, then we should definitely start considering adding roles and playbooks to the collection. It would be awesome if you could collaborate with that - or if you are feeling brave, to start collaborating now .
You might also want to join the Ansible Forum (Discourse, just like this one), or the Matrix chat for Ansible and announce your playbooks.
Again, thank you very much for sharing and for using the collection. If you bump into any bug, or feel like we could add some feature, by all means, go to the community.openwrt git repo and raise an issue. Or a Pull Request ;-).