我想通过使用 Ansible 从控制节点复制 python 程序来在远程节点上运行 python 程序。
我能够成功复制文件,但是它没有在远程服务器上执行 python 程序。
错误:“无法在 Ansible 控制器上找到或访问‘/home/remote/files/program.py’
- 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'
答案 0 :(得分:0)
你的复制目标是/home/remote/files/program.py
您的脚本调用使用 /home/pi/files/program.py
所以你必须修正路径。
答案 1 :(得分:0)
使用 Shell 模块,我能够运行 python 程序。
shell:
cmd: python3 program.py
chdir: /home/ubuntu/files/