0

I am currently working on ansible automation for running a task on remote host. I've done all preparing work such as SSH configuration and all works perfect until I meet the issue which says illegal instruction /usr/bin/python. I doubt it probably is caused by the Environment on the remote host so that I put this command on the file /etc/bashrc:

"load /etc/bashrc
----SOME----
----ORIGINAL----
----CONFIGURATION----
export PATH=/usr/bin/pyhon:$PATH
echo "${PATH}"

I test this and it works, however, I still get the issue which means, my problem is still there.

my source error shows below:

Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
<10.129.145.65> ESTABLISH SSH CONNECTION FOR USER: appuser
<10.129.145.65> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=appuser -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/59a8ca37f8 10.129.145.65 '/bin/sh -c '"'"'sudo -H -S -n-u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-wlljicrcltceaiewolenureccrzbsuoy; /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<10.129.145.65> (132, 'load /etc/bashrc\n/usr/bin/python:/usr/local/bin:/usr/bin\n', '/bin/sh: line 1: 13008 Illegal instruction     /usr/bin/python\n')
fatal: [10.129.145.65]: FAILED! => {
    "changed": false,
    "module_stderr": "/bin/sh: line 1: 13008 Illegal instruction     /usr/bin/python\n",
    "module_stdout": "load /etc/bashrc\n/usr/bin/python:/usr/local/bin:/usr/bin\n",
    "msg": "MODULE FAILURE",
    "rc": 132
}
here I just want to update more about my question and hopefully this can clarify my issue better:
my ansible version is 2.5.0 and python version is 2.7.15

below is my root task:
---
- name: connect to docker build server
  hosts: "hostname1"
  remote_user: appuser
#  hosts: 127.0.0.1
  become: yes
  become_user: root

  vars_files:
  - group_vars/{{docker_env}}/all.yml

  roles:
  - { role: commit-push-docker-images, tags: ['commit-push-docker-images'] }


vars_files contains all variables that are used in my task;

Following code comes from roles : commit-push-docker-images
---
- debug: msg="start to commit docker image and push to harbor"

- name: get json from remote
  uri:
    url: "http://URL_FOR_GETTING_JSON_OBJECT"
    user: "USER_NAME"
    password: "USER_PASSWORD"
    method: GET
    body_format: json
  register: json_response

  ... ( following with some other tasks)

if I try to run my code on 127.0.0.1 and it works!! but if I try to connect to remote host called hostname1, which will incur the error I previouly rendered. What I posted before is the result that I run with -vvv.

Plz tell me if I provided enough info for my question. Thanks a lot!!!

1
  • can any one help me on this to save my life since I've struggled on this issue for several days... Commented Sep 13, 2019 at 8:37

1 Answer 1

0

We need to split things up:

  • When you add something to $PATH it's always folders, not executables. So remove "export PATH=/usr/bin/pyhon:PATH" from your bashrc
  • /usr/bin should be in your $PATH by default so your addition to bashrc is unnecessary
  • Always include your Ansible version and a code snippet of your playbooks

If you need to specify a custom path to a Python executable Ansible has a variable you can set:

ansible_python_interpreter=/mycustomdir/python

This can go in in specific host_vars or group_vars or if all your hosts have this custom path it can go in group_vars/all

If you have that variable set and it still doesn't work, copy the task that is generating the error in a seperate playbook and run it with -vvvv . Add the result to your post.

On your Ansible controller do "export ANSIBLE_KEEP_REMOTE_FILES=1" in your shell and run the test playbook again. This will leave the python files on the remote host. Then try running the python files left in the folder ~/.ansible/tmp/ (homefolder of your ansible user). Python will crash and you can get a better error message or worst case debug it with gdb.

9
  • Hey @HoD, thanks a lot for your reply!! I just updated my question and here I want to add something more. 1. python executable location are exact same both in local(within ansible container) host and in remote host(hostname1); So it doesn't make sense that my progrom work well in my local host while it doesn't in remote host.2.I tried run with -vvvv even before I posted my question, and it turned out quite a large amount of logs.I read that debug log line by line and all seems fine before I get this error, so I just pasted the error that I got with -vvv to make my issue more straightforward. Commented Sep 15, 2019 at 6:53
  • I rewrote my answer and left out an important bit.. You need to first remove the export command from your bashrc , because you added /usr/bin/PYTHON and not /usr/bin bash is producing an error before Ansible can do anything. Then run it again and we should see a different error message.
    – HoD
    Commented Sep 16, 2019 at 8:41
  • I deleted all changed that I've made before, and the error is still there...plz have a look.. fatal: [10.129.145.65]: FAILED! => { "changed": false, "module_stderr": "/bin/sh: line 1: 8605 Illegal instruction /usr/bin/python\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 132 } Commented Sep 16, 2019 at 9:27
  • OK just to be sure: ssh to the remote host and execute /usr/bin/python It sounds like your python is broken and crashing.
    – HoD
    Commented Sep 16, 2019 at 11:12
  • I've done that before I posted my question here, and it worked just fine after I ssh to remote host and execute /usr/bin/python. I doubted that it may be the reason of the bin/sh but I just don't know the exact reason. Actually the python version on the remote host is the same as that on my local environment. Commented Sep 16, 2019 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .