OpenWrt Ansible with Python Requirements

Dear Community

As there is a lack of information about what is really necessary to run ansible against an OpenWrt host (probably for people who do not want to use a workaround like Gekmihesg's Ansible module ansible-openwrt <- nothing against it by the way), I wanted to share my thoughts and experiences with you.

From the ansible website its surely clear that we obviously need some sort of python version

A good read about what python(3) packages are available on OpenWrt can be found on the OpenWrt Website itself (However I could not find the python-mini or python3-mini yet).

The necessary minimally required packages installed on the OpenWrt Router are the following so far

  • python3-light
  • python3-multiprocessing
  • python3-distutils
  • openssh-sftp-server (optional, to get rid of the sftp warning ;))

I tested gather_facts: True and the copy: module so far, and both worked well.

If I find time, i will test more modules and extend the read.

I am also happy to have some replies if I missed some things.

Do we have some experienced Ansible + OpenWrt users who can share some insights and thoughts, then feel free to add some more informations below. :grinning: :smiley:

Thanks and kind regards

1 Like

Today I figured out that i also need to have the following package

  • python3-logging

So in addition to the above packages list this is required too.

What I did today was copying a letsencrypt certificate and key file and did a restart of the uhttpd service.

I had time to dig into that and came up with the following ansible role:

This far all of my basic playbooks that I need for OpenWRT were working. Installing openssh-server, creating users, configuring dotfiles for users, ...

2 Likes

Thank you for this list, I always just installed python3 but my devices don't lack storage, so...
Yet I maybe able to lower the minimal requirements for my OpenWrt Ansible collection:

I wrote this collection from scratch and it's already really versatile, meaning the list of supported UCI sections is quite long. I also plan to extend it even further.
I'm working with templates so the configuration files are being written by Ansible. This has the nice effect that they are a bit more tidy in contrast to what you find on regular devices.

All my OpenWrt hosts in my LAN and in data center I manage with this very collection. The documentation currently is German only but I plan to translate it into English, time is rare you know.
https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection
Can of course be translated with Google and stuff.

I also made some videos:

2 Likes

@johanneskastl Thats great, thanks for sharing. Did not know about the fact of raw commands and that they do not require python for ansible if I understand it correctly. Its a nice trick and great idea. Thanks a lot. I will keep that in mind and mark it as solution.

Hello @pmisch you are welcome. And thanks a lot for sharing your role. I hope I find time to dig into that. At work I have no limitation of ressources as well :sweat_smile: but for my home automation you see with my Linksys its getting quite tricky :blush:.

I'm sorry python IS required for my Ansible collection. But as you stated you don't have to install the whole and spacy python3 package in order for it to work.

Edit:
Well I just tried that and it didn't work. I had to do opkg install python3 in order for all to work.

No no sorry for misunderstanding, I am pretty sure YOU need python :sweat_smile: for your role @pmisch , however the previous Post was intended for @johanneskastl because he is using only raw: commands in his role, thats why I was guessing that HE does not need to have python for staging, as it does not make sense otherwise.

I was answering two post at the same time, probably that was a bit confusing :upside_down_face:

And his solution could probably be integrated in your collection to not install python manually first. Beside of that as a nice side effect having a lower footprint as well.

So both of you great work and great input.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.