How to use Ansible Modules without Python installed

How to use Ansible Modules without Python and a package manager.

How to use Ansible Modules without Python installed

Okay, the title might not be 100% correct. A bit of clickbait ๐Ÿ˜‰

I had to deal with a distro for containers that did not have Python installed and also did not have a package manager. In my case, it was Flatcar Linux (once CoreOS).

In the beginning Ansible raw commands did work but at some point, it got too complex and unreliable.

I have written about how to reboot a machine with Ansible raw command here:

I asked myself: How I could use modules without having a package manager?

I found PyPy. You can just download and extract that archive on your host and you have a fully working Python environment.

Here is a small Ansible playbook on how to install PyPy via Ansible raw commands:

- name: Add pypy to flatcar
  gather_facts: false
  hosts: all
    pypy_version: pypy3.9-v7.3.9-linux64

    - name: Download pypy archive
      raw: wget -q -P /opt/{{ pypy_version }}.tar.bz2

    - name: Extract pypy archive
      raw: tar -xf /opt/{{ pypy_version }}.tar.bz2 -C /opt

    - name: Remove archive
      raw: rm -rf /opt/{{ pypy_version }}.tar.bz2

    - name: Create /opt/bin for older
      raw: mkdir -p /opt/bin

    - name: Create symlink for python
      raw: ln -s  /opt/{{ pypy_version }}/bin/python /opt/bin/python

And here you can finally โ€‹use Ansible module actions. Just remember to specify the Python path for Ansible:

- name: Reboot flatcar
  hosts: all
  remote_user: root
  gather_facts: yes
    ansible_python_interpreter: /opt/bin/python

    - name: Going for a reboot แ••( แ› )แ•—
        reboot_timeout: 600

Last Words

How am I doing?

I love hearing from readers, and I am always looking for feedback.
Click on the ๐Ÿ‘ or ๐Ÿ‘Ž down below, it is that easy.

What do you enjoy most about the newsletter, just let me know in the comments.

Have a great day! ๐Ÿ‘‹