0
votes

I would like to run the python program on a remote node by copying the python program from control node using Ansible.

I was able to copy the file successfully, however it is not executing the python program on the remote server.

Error: "Could not find or access '/home/remote/files/program.py' on the Ansible Controller

- name: copy the program file to ubuntu
  copy:
    src: /home/ubuntu/ansible/program.py
    dest: /home/remote/files/program.py
    mode: '0777'
  when: ansible_user== 'remote'
- name: Run the python script in remote
  script: /home/pi/files/program.py
  args:
    executable: python3
  when: ansible_user== 'remote'
2
script - Runs a local script on a remote node after transferring it from this link.docs.ansible.com/ansible/2.4/script_module.html so either change your script path to controller node's location, or use command or shell module to execute already copied script on remote machine - JBone

2 Answers

1
votes

Using Shell module I was able to run the python program.

shell:
  cmd: python3 program.py
  chdir: /home/ubuntu/files/
0
votes

Your copy destination is /home/remote/files/program.py

Your script call use /home/pi/files/program.py

So you have to fix the path.