Directory Structure:
|-- Script
| |-- Name.py
| |-- Name.pyc
| |-- Test.py
| |-- __init__.py
| `-- __pycache__
| `-- Name.cpython-36.pyc
|-- SimplePlaybook.yml
|-- ansible.cfg
|-- ansible_log.log
|-- hosts
Script Folder:
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})
Playbook:
---
-
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
...
I am getting an import error.
Issue:
import error of Name.py, module not found
Debug Observation:
when ansible run the Test.py file it runs from the path like below location
ansible/tmp/ansible-xxxx
I tried to add that path in python path but still got an import error of Name.py
need inputs here to resolve this issue.