首页 > 解决方案 > 如何在 Ansible 中的远程节点上执行 python 程序

问题描述

我想通过使用 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'

标签: ansible

解决方案


使用 Shell 模块,我能够运行 python 程序。

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

推荐阅读