gekmihesg/ansible-openwrt

`service` fails on second host

giorgiga opened this issue · 4 comments

I'm using

- name: disable services
  service:
    name: "{{ item }}"
    enabled: no
    state: stopped
  loop:
    - odhcpd
    - dnsmasq
    - firewall

for my two wifi access points.

Whenever I run ansible targeting both hosts, the task succeeds on the first AP, but always fails on the second with:

failed: [ap2] (item=dnsmasq) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "dnsmasq",
    "rc": 127
}

MSG:

The module failed to execute correctly, you probably need to set the interpreter.
See stdout/stderr for the exact error


MODULE_STDOUT:

/bin/sh: /usr/bin/python: not found

If I run ansible with --limit either one of the two APs (tried both) it works flawlessly.

ansible 2.12.17 on Fedora f36 with latest gekmihesg.ansible-openwrt

Here-s the error with -vvv:

<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' 192.168.10.4 '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<192.168.10.4> (0, b'/root\n', b'')
<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' 192.168.10.4 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196 `" && echo ansible-tmp-1663602966.7170982-97912-68375861885196="` echo /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196 `" ) && sleep 0'"'"''
<192.168.10.4> (0, b'ansible-tmp-1663602966.7170982-97912-68375861885196=/root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196\n', b'')
Using module file /usr/lib/python3.10/site-packages/ansible/modules/setup.py
<192.168.10.4> PUT /home/user/.ansible/tmp/ansible-local-978532ta7wexa/tmp_twr9xuh TO /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_setup.py
<192.168.10.4> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' '[192.168.10.4]'
<192.168.10.4> (0, b'sftp> put /home/user/.ansible/tmp/ansible-local-978532ta7wexa/tmp_twr9xuh /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_setup.py\n', b'')
<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' 192.168.10.4 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/ /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_setup.py && sleep 0'"'"''
<192.168.10.4> (0, b'', b'')
<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' -tt 192.168.10.4 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_setup.py && sleep 0'"'"''
<192.168.10.4> (127, b'/bin/sh: /usr/bin/python: not found\r\n', b'')
<192.168.10.4> Failed to connect to the host via ssh: 
Using module file /usr/lib/python3.10/site-packages/ansible/modules/service.py
<192.168.10.4> PUT /home/user/.ansible/tmp/ansible-local-978532ta7wexa/tmpl0e7w_be TO /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_service.py
<192.168.10.4> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' '[192.168.10.4]'
<192.168.10.4> (0, b'sftp> put /home/user/.ansible/tmp/ansible-local-978532ta7wexa/tmpl0e7w_be /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_service.py\n', b'')
<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' 192.168.10.4 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/ /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_service.py && sleep 0'"'"''
<192.168.10.4> (0, b'', b'')
<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' -tt 192.168.10.4 '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/AnsiballZ_service.py && sleep 0'"'"''
<192.168.10.4> (127, b'/bin/sh: /usr/bin/python: not found\r\n', b'')
<192.168.10.4> Failed to connect to the host via ssh: 
<192.168.10.4> ESTABLISH SSH CONNECTION FOR USER: root
<192.168.10.4> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/user/.ansible/cp/27486f69ae"' 192.168.10.4 '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1663602966.7170982-97912-68375861885196/ > /dev/null 2>&1 && sleep 0'"'"''
<192.168.10.4> (0, b'', b'')
failed: [ap2] (item=firewall) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "firewall",
    "rc": 127
}

MSG:

The module failed to execute correctly, you probably need to set the interpreter.
See stdout/stderr for the exact error


MODULE_STDOUT:

/bin/sh: /usr/bin/python: not found

It seems like it tries to use ansible's default service instead of the openwrt one? (Using module file /usr/lib/python3.10/site-packages/ansible/modules/service.py)

@giorgiga how to solve it, same error when i use loop with include_tasks,
It loads the default module ‘ansible/modules/command.py’ instead of ‘.ansible/roles/gekmihesg.openwrt/library/openwrt_command.sh’

<k3.lan> ESTABLISH SSH CONNECTION FOR USER: root
<k3.lan> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<k3.lan> SSH: ansible_password/ansible_ssh_password not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<k3.lan> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User="root")
<k3.lan> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)
<k3.lan> SSH: Set ssh_common_args: ()
<k3.lan> SSH: Set ssh_extra_args: ()
<k3.lan> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath="/home/xy/.ansible/cp/4cac8dd90a")
<k3.lan> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/xy/.ansible/cp/4cac8dd90a"' k3.lan '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /tmp `"&& mkdir "` echo /tmp/ansible-tmp-1695707915.855962-11849-27404775912062 `" && echo ansible-tmp-1695707915.855962-11849-27404775912062="` echo /tmp/ansible-tmp-1695707915.855962-11849-27404775912062 `" ) && sleep 0'"'"''
<k3.lan> (0, b'ansible-tmp-1695707915.855962-11849-27404775912062=/tmp/ansible-tmp-1695707915.855962-11849-27404775912062\n', b"OpenSSH_9.2p1 Debian-2, OpenSSL 3.0.9 30 May 2023\r\ndebug1: Reading configuration data /home/xy/.ssh/config\r\ndebug1: /home/xy/.ssh/config line 10: Applying options for k3.lan\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/xy/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/xy/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 11719\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
Including module_utils file ansible/__init__.py
Including module_utils file ansible/module_utils/__init__.py
Including module_utils file ansible/module_utils/_text.py
Including module_utils file ansible/module_utils/basic.py
Including module_utils file ansible/module_utils/common/_json_compat.py
Including module_utils file ansible/module_utils/common/__init__.py
Including module_utils file ansible/module_utils/common/_utils.py
Including module_utils file ansible/module_utils/common/arg_spec.py
Including module_utils file ansible/module_utils/common/collections.py
Including module_utils file ansible/module_utils/common/file.py
Including module_utils file ansible/module_utils/common/locale.py
Including module_utils file ansible/module_utils/common/parameters.py
Including module_utils file ansible/module_utils/common/process.py
Including module_utils file ansible/module_utils/common/sys_info.py
Including module_utils file ansible/module_utils/common/text/converters.py
Including module_utils file ansible/module_utils/common/text/__init__.py
Including module_utils file ansible/module_utils/common/text/formatters.py
Including module_utils file ansible/module_utils/common/validation.py
Including module_utils file ansible/module_utils/common/warnings.py
Including module_utils file ansible/module_utils/compat/selectors.py
Including module_utils file ansible/module_utils/compat/__init__.py
Including module_utils file ansible/module_utils/compat/_selectors2.py
Including module_utils file ansible/module_utils/compat/selinux.py
Including module_utils file ansible/module_utils/distro/__init__.py
Including module_utils file ansible/module_utils/distro/_distro.py
Including module_utils file ansible/module_utils/errors.py
Including module_utils file ansible/module_utils/parsing/convert_bool.py
Including module_utils file ansible/module_utils/parsing/__init__.py
Including module_utils file ansible/module_utils/pycompat24.py
Including module_utils file ansible/module_utils/six/__init__.py
<k3.lan> Attempting python interpreter discovery
<k3.lan> ESTABLISH SSH CONNECTION FOR USER: root
<k3.lan> SSH: ansible.cfg set ssh_args: (-C)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s)
<k3.lan> SSH: ansible_password/ansible_ssh_password not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no)
<k3.lan> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User="root")
<k3.lan> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10)
<k3.lan> SSH: Set ssh_common_args: ()
<k3.lan> SSH: Set ssh_extra_args: ()
<k3.lan> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath="/home/xy/.ansible/cp/4cac8dd90a")
<k3.lan> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/xy/.ansible/cp/4cac8dd90a"' k3.lan '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.11'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.5'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<k3.lan> (0, b'PLATFORM\nLinux\nFOUND\nENDFOUND\n', b"OpenSSH_9.2p1 Debian-2, OpenSSL 3.0.9 30 May 2023\r\ndebug1: Reading configuration data /home/xy/.ssh/config\r\ndebug1: /home/xy/.ssh/config line 10: Applying options for k3.lan\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/xy/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/xy/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 11719\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
Using module file /home/xy/.local/lib/python3.11/site-packages/ansible/modules/command.py

Personally, I've ended up ditching ansible and building custom openwrt images with the imagebuilder instead: running ansible without python on the target host is just too much of a pain.

PS: IDK why it says I've closed this issue... I must have closed it when I was high :)