I have an ansible server that I find works fine, but when I try to run a python script on the deployed servers I get no such file or directory
, even though I visually confirm they are there.
Here's my anisble playbook code:
create a user directory and a dev subdirectory
- name: Create directory for python files
file: path=/home/{{ user_name }}/python_files
state=directory
owner={{ user_name }}
group={{ user_name }}
mode=755
- name: Copy python file over
copy:
src=example.py
dest=/home/{{ user_name }}/python_files/example.py
owner={{ user_name }}
group={{ user_name }}
mode=777
- name: Execute script
command: /home/{{ user_name }}/python_files/example.py
This is the error I get:
TASK [python-dev : Execute script] *********************************************
task path: /usr/share/ansible-demo/roles/python-dev/tasks/main.yml:37
<192.168.1.240> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.240> SSH: EXEC sshpass -d14 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o ConnectTimeout=10 -o ControlPath=/home/achilles/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.1.240 '/bin/sh -c '"'"'( umask 22 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1460496110.48-100414848375832 `" && echo "` echo $HOME/.ansible/tmp/ansible-tmp-1460496110.48-100414848375832 `" )'"'"''
<192.168.1.240> PUT /tmp/tmpcLPC60 TO /home/achilles/.ansible/tmp/ansible-tmp-1460496110.48-100414848375832/command
<192.168.1.240> SSH: EXEC sshpass -d14 sftp -b - -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o ConnectTimeout=10 -o ControlPath=/home/achilles/.ansible/cp/ansible-ssh-%h-%p-%r '[192.168.1.240]'
<192.168.1.240> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.1.240> SSH: EXEC sshpass -d14 ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o ConnectTimeout=10 -o ControlPath=/home/achilles/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.1.240 '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=dbpmnfbipbkpualueeaxdbkosbjdwsdk] password: " -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-dbpmnfbipbkpualueeaxdbkosbjdwsdk; /bin/sh -c '"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/achilles/.ansible/tmp/ansible-tmp-1460496110.48-100414848375832/command; rm -rf "/home/achilles/.ansible/tmp/ansible-tmp-1460496110.48-100414848375832/" > /dev/null 2>&1'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"'"''"'"'"'"'"'"'"'"''"'"''
fatal: [192.168.1.240]: FAILED! => {"changed": false, "cmd": "/home/achilles/python_files/example.py", "failed": true, "invocation": {"module_args": {"_raw_params": "/home/achilles/python_files/example.py", "_uses_shell": false, "chdir": null, "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "msg": "[Errno 2] No such file or directory", "rc": 2}
The directory permissions look ok on the deployed server:
achilles@ansible-test:~/python_files$ ll
total 12
drwxr-xr-x 2 achilles achilles 4096 Apr 12 15:56 ./
drwxr-xr-x 18 achilles achilles 4096 Apr 12 15:56 ../
-rwxrwxrwx 1 achilles achilles 153 Apr 12 15:56 example.py*
Any suggestions? I don't think I overlooked the obvious but I am fairly new to ansible and this link didn't help.