jagatjyoti
jagatjyoti

Reputation: 717

Ansible playbook script failure

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 !

Upvotes: 0

Views: 1946

Answers (2)

udondan
udondan

Reputation: 59989

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 }}"

Upvotes: 1

Arbab Nazar
Arbab Nazar

Reputation: 23771

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

Upvotes: 0

Related Questions