这是在Linux机器上。我有这样的run.yml
---
- name: Appspec
hosts: localhost
become: true
tasks:
- name: test 1
script: test.py
test.py通过'import helper'使用python文件(helper.py),该文件与ansible-playbook处于同一路径,并且在运行playbook.yml时,仍然给我一个'导入错误:无法导入名称帮手'。我该怎么办?
答案 0 :(得分:1)
将test.py
和helper.py
复制到远程计算机上的同一目录(可能复制到临时目录)中,并将python test.py
作为command
任务运行。像这样:
- name: Create temporary directory
tempfile:
state: directory
register: tmpdir
- name: Copy test.py
copy:
src: /wherever/test.py
dest: "{{tmpdir.path}}/test.py"
- name: Copy helper.py
copy:
src: /wherever/helper.py
dest: "{{tmpdir.path}}/helper.py"
- name: Run test.py
command: python test.py
args:
chdir: "{{tmpdir.path}}"