Use Ansible to manage LXC containers on Turris OS

Hi!

One of my projects on Turris Omnia is to manage the deployment of LXC containers through Ansible.
Thus, I plan to use the lxc_container module of Ansible, which requires the installation of python3-lxc on the Turris Omnia host.

Unfortunately, python3-lxc is available neither through a system package (opkg) nor through pip (it does have lxc-python2, but no lxc-python3.

So I decided to compile python3-lxc from source by myself, then to install it on my Turris Omnia host. For that build purpose, I created a temporary LXC container with a Turris OS image, then:

  • Downloaded the source of python3-lxc v3.0.4
  • Installed pkg-config, python3-setuptools, python3-dev, gcc, make in the container
  • Copied the header files (src/lxc/*.h) from LXC source in version 3.0.3, as there is no “dev” package available through opkg and that this tag matches the actual version of lxc package. I copied these files in /usr/include/lxc/, as they are required for the build.
  • Launched python3 setup.py build from python3-lxc source directory

And here is the result:

running build
running build_py
warning: build_py: byte-compiling is disabled, skipping.

running build_ext
Package lxc was not found in the pkg-config search path.
Perhaps you should add the directory containing `lxc.pc'
to the PKG_CONFIG_PATH environment variable
No package 'lxc' found
building '_lxc' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -iremap/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/Python-3.7.10:Python-3.7.10 -Wformat -Werror=format-security -fpic -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,now -Wl,-z,relro -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -iremap/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/Python-3.7.10:Python-3.7.10 -Wformat -Werror=format-security -fpic -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -Os -pipe -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=hard -iremap/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/Python-3.7.10:Python-3.7.10 -Wformat -Werror=format-security -fpic -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -I/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/usr/include -I/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/include -I/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/usr/include -I/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/include/fortify -I/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/include -fPIC -I/usr/include/python3.7 -c lxc.c -o build/temp.linux-armv7l-3.7/lxc.o
[...]
gcc -shared -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/usr/lib -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/lib -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/usr/lib -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/lib -fpic -specs=/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/include/hardened-ld-pie.specs -znow -zrelro -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/Python-3.7.10 -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/usr/lib -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/lib -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/usr/lib -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/staging_dir/toolchain-arm_cortex-a9+vfpv3-d16_gcc-7.5.0_musl_eabi/lib -fpic -specs=/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/include/hardened-ld-pie.specs -znow -zrelro -L/home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/build_dir/target-arm_cortex-a9+vfpv3-d16_musl_eabi/Python-3.7.10 build/temp.linux-armv7l-3.7/lxc.o -L/usr/lib -llxc -lpython3.7 -o build/lib.linux-armv7l-3.7/_lxc.cpython-37.so
gcc: error: /home/beast/beast/workspace/turris-os-packages-kittens-omnia/build/include/hardened-ld-pie.specs: No such file or directory
error: command 'gcc' failed with exit status 1

I am not used to the setuptools toolchain, so I wonder why there are so many references to /home/beast/beast/workspace/turris-os-packages-kittens-omnia/ in the gcc calls, but obviously I have no such directory in my system.
How can I sort this out? What am I missing?

Do you think I am on the right path to get a compiled python3-lxc installed on my Turris Omnia router? Or is there a simpler and/or more efficient approach?

Thanks in advance!

Some of the dependencies probably “cached/saved” settings during the official build (which is a cross-build from x86_64). I’m not really able to help solving this, though.

The same errors occurs on 5.2.4.

As workaround i manually create containers (Alpine) and

  • unlock root account
  • copy an ssh key
  • install & start openssh
    but python3-lxc would be better :smiley:

After few commands, it appears some python variables are incorrectly set.

Python 3.7.11 (default, Jul 25 2021, 22:46:25)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils import sysconfig
>>> sysconfig.get_config_vars()
[ and the beast appears in the block ]

Doc: 9. Référence de l'API — Documentation Python 3.9.6

I create Issue #810 on gitlab

I am using ansible but with ssh keys and openssh server on the container. I didn’t even know there is other way possible.

And I think you should crosscompile on your desktop not to try to compile it on Omnia.

Edit: Subscribed to the subject!