# OpenWrt Ansible with Python Requirements

**URL:** <https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207>\
**Category:** For Developers\
**Created:** [January 23, 2022, 6:55pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207 "2022-01-23T18:55:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tschabadu](https://forum.openwrt.org/user_avatar/forum.openwrt.org/tschabadu/32/47981_2.png) [@Tschabadu](https://forum.openwrt.org/u/Tschabadu)\
**Post date:** [January 23, 2022, 6:55pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/1 "2022-01-23T18:55:22Z")

</div>

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](https://github.com/gekmihesg/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

- [Managed Node Requirements](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#managed-node-requirements)

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).

- [OpenWrt Python Packages](https://openwrt.org/docs/guide-user/services/python)

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. 😀 😃

Thanks and kind regards

---

<div class="post-metadata">

**Author:** ![Tschabadu](https://forum.openwrt.org/user_avatar/forum.openwrt.org/tschabadu/32/47981_2.png) [@Tschabadu](https://forum.openwrt.org/u/Tschabadu)\
**Post date:** [January 30, 2022, 1:52pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/2 "2022-01-30T13:52:29Z")

</div>

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**.

---

<div class="post-metadata">

**Author:** ![johanneskastl](https://forum.openwrt.org/user_avatar/forum.openwrt.org/johanneskastl/32/48304_2.png) [@johanneskastl](https://forum.openwrt.org/u/johanneskastl)\
**Post date:** [February 4, 2022, 2:04pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/3 "2022-02-04T14:04:26Z")

</div>

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

> **[GitHub - johanneskastl/ansible-role-bootstrap\_python\_on\_OpenWRT: Install...](https://github.com/johanneskastl/ansible-role-bootstrap_python_on_OpenWRT)**
>
> Install python3 and other packages needed for managing OpenWRT via ansible - GitHub - johanneskastl/ansible-role-bootstrap\_python\_on\_OpenWRT: Install python3 and other packages needed for managing ...

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

---

<div class="post-metadata">

**Author:** ![pmisch](https://forum.openwrt.org/user_avatar/forum.openwrt.org/pmisch/32/127705_2.png) [@pmisch](https://forum.openwrt.org/u/pmisch)\
**Post date:** [February 4, 2022, 4:32pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/4 "2022-02-04T16:32:06Z")

</div>

> [@Tschabadu](#):
>
> The necessary **minimally required packages**

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:

> **[GitHub - imp1sh/ansible\_openwrt: ansible\_openwrt is a full featured openwrt...](https://github.com/imp1sh/ansible_openwrt)**
>
> ansible\_openwrt is a full featured openwrt collection. It relies on python so you need enough flash space in order to be able to use it. - GitHub - imp1sh/ansible\_openwrt: ansible\_openwrt is a full...

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](https://wiki.junicast.de/de/junicast/docs/AnsibleOpenWrtCollection)  
Can of course be translated with Google and stuff.

I also made some videos:

- [https://youtu.be/-H1-akQIaCA](https://youtu.be/-H1-akQIaCA) (English)
- [https://youtu.be/f1qrP3AagLM](https://youtu.be/f1qrP3AagLM) (German)

---

<div class="post-metadata">

**Author:** ![Tschabadu](https://forum.openwrt.org/user_avatar/forum.openwrt.org/tschabadu/32/47981_2.png) [@Tschabadu](https://forum.openwrt.org/u/Tschabadu)\
**Post date:** [February 6, 2022, 10:27am UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/5 "2022-02-06T10:27:20Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Tschabadu](https://forum.openwrt.org/user_avatar/forum.openwrt.org/tschabadu/32/47981_2.png) [@Tschabadu](https://forum.openwrt.org/u/Tschabadu)\
**Post date:** [February 6, 2022, 10:38am UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/6 "2022-02-06T10:38:52Z")

</div>

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 😅 but for my home automation you see with my Linksys its getting quite tricky 😊.

---

<div class="post-metadata">

**Author:** ![pmisch](https://forum.openwrt.org/user_avatar/forum.openwrt.org/pmisch/32/127705_2.png) [@pmisch](https://forum.openwrt.org/u/pmisch)\
**Post date:** [February 6, 2022, 12:33pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/7 "2022-02-06T12:33:01Z")

</div>

> [@Tschabadu](#):
>
> that they do not require python

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.

---

<div class="post-metadata">

**Author:** ![Tschabadu](https://forum.openwrt.org/user_avatar/forum.openwrt.org/tschabadu/32/47981_2.png) [@Tschabadu](https://forum.openwrt.org/u/Tschabadu)\
**Post date:** [February 6, 2022, 2:59pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/8 "2022-02-06T14:59:13Z")

</div>

> [@pmisch](#):
>
> I'm sorry python IS required for my Ansible collection.

No no sorry for misunderstanding, I am pretty sure **YOU** need python 😅 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 🙃

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.

---

<div class="post-metadata">

**Author:** ![system](https://forum.openwrt.org/uploads/default/original/3X/7/4/740520c71f00039bbf001045c682f0ecb25e905a.png) [@system](https://forum.openwrt.org/u/system)\
**Post date:** [February 16, 2022, 2:59pm UTC](https://forum.openwrt.org/t/openwrt-ansible-with-python-requirements/118207/9 "2022-02-16T14:59:36Z")

</div>

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