The issue still there, so I have moved the playbook file to the same 
directory where python script is running ex: /reports/

So both playbook and python script is in the same folder. But still, I get 
a couple of errors.

Below is my playbook:
********************
---
- hosts: switch1
  vars:
   ansible_connection: network_cli
   ansible_network_os: nxos
   ansible_ssh_user: '{{ username }}'
   ansible_ssh_pass: '{{ password }}'
  tasks:
   - name: Execute the test1 script
     command: python /home/{{ username }}/project1/reports/test1.py --- 
python script running on same folder as yaml playbook
     delegate_to:
     args:
       chdir: /home/{{ username }}/project1/reports/
    ignore_errors: False


I get a couple of error if I run the playbook with commenting (#) args: 
chdir: then i get.

fatal: [switch1]: FAILED! => {"changed": true, "cmd": ["python", "/home/{{ 
username }}/project1/reports/test1.py"], "delta": "0:00:00.035644", "end": 
"2020-05-28 19:04:00.583497", "msg": "non-zero return code", "rc": 2, 
"start": "2020-05-28 19:04:00.547853", "stderr": "python: can't open file 

If i uncomment(remove # on those lines) the args: chdir: then i get.

fatal: [switch1]: FAILED! => {"changed": false, "msg": "Unable to change 
directory before execution: [Errno 2] No such file or directory: '/home/{{ 
username }}/project1/reports/'"}


Python - unable to identify the path to execute the test1.py that i finally 
understood. so any permission to the user to execute the same or do i need 
to move the playbook to back to original directory, so the python script is 
under subdirectory.

Please suggest. if am missing any logic here.

On Wednesday, May 27, 2020 at 12:31:40 PM UTC+2, aditya govindaraju wrote:
>
> Am trying to write a playbook in order to execute a python script running 
> on a different subdirectory under the same project folder
>
> A python script running on - /home/{username}/project1/reports/test1.py
>
> And playbook running on - /home/{username}/project1/test1.yml
>
> I need to execute a python script using the playbook. And playbook looks 
> like this.
>
> ---
> - hosts: switch1
>   vars:
>    ansible_connection: network_cli
>    ansible_network_os: nxos
>    ansible_ssh_user: '{{ username }}'
>    ansible_ssh_pass: '{{ password }}'
>   tasks:
>    - name: Execute the python script
>      command: python test1.py
>      args:
>        chdir: /home/{username}/project1/reports
>
>
> But it's failing to execute the script. Please suggest me if am missing 
> anything
>
>
>
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/83c38126-78d3-44e7-96e6-dcc37fd66de4%40googlegroups.com.

Reply via email to