问题描述
目录结构:
|-- Script
| |-- Name.py
| |-- Name.pyc
| |-- Test.py
| |-- __init__.py
| `-- __pycache__
| `-- Name.cpython-36.pyc
|-- SimplePlaybook.yml
|-- ansible.cfg
|-- ansible_log.log
|-- hosts
脚本文件夹:
Name.py
student_name = "Jhon Doe"
Test.py
import Name
print("My Name is %s \n" % Name.student_name)
sys.exit({"rc": 0,"changed": True})
剧本:
---
-
hosts: HOST
gather_facts: True
tasks:
- name: Print Gathered Facts
debug:
var: hostvars
- debug:
msg: "{{ playbook_dir }}"
- name: Run Test Script
script: "{{ playbook_dir }}/Script/Test.py"
register: result
args:
executable: python3
- debug:
var: result
...
我收到导入错误。
问题:
Name.py导入错误,找不到模块
调试观察:
当ansible运行Test.py
文件时,它将从以下位置运行
ansible/tmp/ansible-xxxx
我试图在python路径中添加该路径,但仍然出现Name.py
此处需要输入以解决此问题。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)