0

Getting error while running below playbook. The python script is on my master and I want it to run on two slaves. No idea what's wrong.

luckee@zarvis:~/playbooks$ ansible-playbook runscript.yml 

PLAY [droplets] ****************************************************************

TASK [setup] *******************************************************************
ok: [CentOS1]
ok: [CentOS2]

TASK [Run python script] *******************************************************
fatal: [CentOS1]: FAILED! => {"changed": false, "cmd": "/home/luckee/python/userfind.py", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
fatal: [CentOS2]: FAILED! => {"changed": false, "cmd": "/home/luckee/python/userfind.py", "failed": true, "msg": "[Errno 2] No such file or directory", "rc": 2}

NO MORE HOSTS LEFT *************************************************************
        to retry, use: --limit @runscript.retry                                                                                                                                                 

PLAY RECAP *********************************************************************                                                                                                                
CentOS1                    : ok=1    changed=0    unreachable=0    failed=1                                                                                                                     
CentOS2                    : ok=1    changed=0    unreachable=0    failed=1                                                                                                                     

luckee@zarvis:~/playbooks$ 

Here is the playbook.

---
 - hosts: droplets
   remote_user: root

   tasks:
   - name: Run python script
     command: /home/luckee/python/userfind.py
...

Looking forward for your help !

1
  • "No idea what's wrong" - well, it says No such file or directory. Try double check the file paths? Commented Jun 19, 2016 at 20:23

2 Answers 2

1

You try to execute a local file on a remote host.

If you meant to run it remotely you first need to transfer it or use the script module. It first transfers the file to the remote hosts and then executes it.

- name: Run python script
  script: /home/luckee/python/userfind.py

If you meant to run the script locally, use delegation:

- name: Run python script
  command: /home/luckee/python/userfind.py
  delegate_to: localhost

To show the output of a task you first need to register the result and the print it out with a debug task.

- name: Any task
  ...
  register: result

- name: Show result
  debug: msg="{{ result.stdout }}"
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, it did work perfectly without any errors. But how can I get the output of the script from the hosts ? For ex - The script above searches for an user and prints something.
You can get the output of any module with register: docs.ansible.com/ansible/… If you want to show the output you can do this with a debug task. I added an example in the answer above.
0

I think first you need to transfer the script to the remote hosts and then run it:

---
 - hosts: droplets
   remote_user: root

   tasks:
   - name: copy the script to the remote host
     copy:
       src: userfind.py
       dest: /tmp/userfind.py
       mode: 0777

   - name: Run python script
     command: python /tmp/userfind.py

Fix the path as per your requirement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.