Skip to content

Instantly share code, notes, and snippets.

@kuttor
Created March 19, 2019 06:04
Show Gist options
  • Save kuttor/5540b0b7ee18ea62283068b03813693e to your computer and use it in GitHub Desktop.
Save kuttor/5540b0b7ee18ea62283068b03813693e to your computer and use it in GitHub Desktop.
Get Ansible working on an Android phone using a Terminal Emulator like Termux
#!/data/data/com.termux/files/usr/bin/bash
yes | pkg upgrade && \
yes | pkg install \
python \
python-dev \
libffi \
libffi-dev \
openssl \
openssl-dev \
libsodium \
clang \
cmake
# Install the latest Python package manager.
# The version of pip that comes with Python may be outdated.
pip install --upgrade pip
pip list --outdated --format=freeze | \
grep -v '^\-e' | \
cut -d = -f 1 | \
xargs -n1 pip install -U && \
# The pynacl dependency originally did not install because
# it gave problems building dependencies'
pip install --upgrade pynacl
pip install --upgrade ansible
@Lennie
Copy link

Lennie commented Jul 8, 2023

Instead of export CARGO_BUILD_TARGET I did pkg install binutils

@phanirithvij
Copy link

phanirithvij commented Jul 11, 2023

@lexxxel I found that this issue occurs only when using connection: local in the playbook. (which is used by ansible -m ping localhost as well I think)
I guess this is a bug in termux as echo ~u0_a510 is ideally supposed to give /data/data/com.termux/files/home but gives /data. (on linux echo ~username does give /home/username if a user named username exists)

I found two ways of working around it.

  • One is to use ssh connection type and pass the localhost/127.0.0.1 from the inventory. (works only for ansible-playbook and doesn't apply for ansible -m setup localhost)
  • Or patch ansible code to have this line added. (Works for me both ansible, ansible-playbook commands with connection: local)
diff --git a/plugins/connection/local.py b/plugins/connection/local.py
index 27afd10..e21c4df 100644
--- a/plugins/connection/local.py
+++ b/plugins/connection/local.py
@@ -42,6 +42,7 @@ class Connection(ConnectionBase):

     transport = 'local'
     has_pipelining = True
+    _remote_is_local = True

     def __init__(self, *args, **kwargs):

Related issues, urls

@lexxxel
Copy link

lexxxel commented Jul 11, 2023

@phanirithvij thank you for your suggestions.
I also tried my production playbook, which uses ssh connections to my proxmox instances. These connections are absolutely instable, like 1 out of 5 work. Which make ansible unusable for me :-(
I will try your fix someday in the next few weeks and post if it helped me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment