jandiorio / ansible-dnac-modules

GNU General Public License v3.0
19 stars 7 forks source link

Use with virtual environment #2

Closed RunSi closed 5 years ago

RunSi commented 5 years ago

Currently trying to use with a Python 2.7 virtual environment. dnac.py has been copied to the virtualenv libs directory.

venv/lib/python2.7/site-packages/ansible/module_utils/network/dnac/

And modules have been copied to

venv/lib/python2.7/site-packages/ansible/plugins/modules/

However when running the playbook am getting the follow error. This seems to point to a path join error


The full traceback is:
Traceback (most recent call last):
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 140, in run
    res = self._execute()
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 612, in _execute
    result = self._handler.run(task_vars=variables)
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/plugins/action/normal.py", line 46, in run
    result = merge_hash(result, self._execute_module(task_vars=task_vars, wrap_async=wrap_async))
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 742, in _execute_module
    (module_style, shebang, module_data, module_path) = self._configure_module(module_name=module_name, module_args=module_args, task_vars=task_vars)
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 178, in _configure_module
    environment=final_environment)
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/executor/module_common.py", line 973, in modify_module
    environment=environment)
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/executor/module_common.py", line 791, in _find_module_utils
    recursive_finder(module_name, b_module_data, py_module_names, py_module_cache, zf)
  File "/Users/sihart/mycode/Ansible_DNAC/venv/lib/python2.7/site-packages/ansible/executor/module_common.py", line 638, in recursive_finder
    [os.path.join(p, *py_pkg_name[:-1]) for p in module_utils_paths])
ImportError: No module named __init__

fatal: [localhost]: FAILED! => {
    "msg": "Unexpected failure during module execution.", 
    "stdout": ""
}
jandiorio commented 5 years ago

sorry for the long delay in response. you need to create an init.py file in the directory where you placed the dnac.py.

The init.py can be empty and you can create it using touch $PATH_TO_FILE/__init__.py