Coder Social home page Coder Social logo

Cannot Use Collection (ModuleNotFoundError: No module named 'ansible_collections') about ansible-galaxy-fortios-collection HOT 6 CLOSED

fortinet-ansible-dev avatar fortinet-ansible-dev commented on July 2, 2024
Cannot Use Collection (ModuleNotFoundError: No module named 'ansible_collections')

from ansible-galaxy-fortios-collection.

Comments (6)

chillancezen avatar chillancezen commented on July 2, 2024

@forestoden
could you dump the Ansible version by $ansible-playbook --version?

from ansible-galaxy-fortios-collection.

forestoden avatar forestoden commented on July 2, 2024

Of course, sorry forgot to include that.

$ansible-playbook --version
ansible-playbook 2.9.11
  config file = None
  configured module search path = ['/Users/forest.oden/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.8.5 (default, Jul 21 2020, 10:48:26) [Clang 11.0.3 (clang-1103.0.32.62)]

from ansible-galaxy-fortios-collection.

mbdraks avatar mbdraks commented on July 2, 2024

@forestoden

One way to troubleshoot this is to create a new environment to test the playbook, here's one way to do it:

  1. Create Dockerfile to build image:
FROM ubuntu:19.10

RUN set -x && \
    \
    echo "==> Installing python3 and dependencies..."  && \
    apt update && \
    apt install python3-pip --yes && \
    \
    echo "==> Installing Ansible..."  && \
    pip3 install ansible && \
    \
    echo "==> Installing Ansible collections..."  && \
    echo "==> specific for FortiOS 6.2..."  && \
    ansible-galaxy collection install fortinet.fortios:1.0.10 && \
    ansible-galaxy collection install fortinet.fortimanager && \

WORKDIR /ansible
  1. Build image and start container

  2. Check if you can see the docs using the full namespace

ansible-doc fortinet.fortios.fortios_system_interface

Using the above process here's the path of my module:

/root/.ansible/collections/ansible_collections/fortinet/fortios/plugins/modules/fortios_system_interface.py

Keep in mind that the ansible-galaxy collection module is not the same that comes shipped with ansible, that one is found here:

root@fc9c76ac267b:/ansible# ansible-doc -F | grep fortios_system_interface
fortios_system_interface                                      /usr/local/lib/python3.7/dist-packages/ansible/modules/network/fortios/fortios_system_interface.py                                  
  1. Use the full name on the task.

Instead of using - collections remove that and use the task with the name fortinet.fortios.fortios_system_interface. Both formats have the same effect.

  1. Make sure your ansible_network_os variable is set to fortinet.fortios.fortios. I had issues in the past using only fortios as it tries to call the older modules.

from ansible-galaxy-fortios-collection.

forestoden avatar forestoden commented on July 2, 2024

Hi @mbdraks, all of the checks you have listed here work as expected in my normal development environment. I did not try to set up a docker dev environment because it seems like my normal one has the collection. I use the collection for a few other tasks in the same playbook, and those actually execute without issue

from ansible-galaxy-fortios-collection.

chillancezen avatar chillancezen commented on July 2, 2024

@mbdraks @forestoden ,
thanks Michel, Forest for the issue,

error No module named 'ansible_collections' usually means environment setup issue. we'd better have a clean environment. here I used a python3 virtual env

#python3 -m venv AnsibleTestEnv
#source AnsibleTestEnv/bin/activate

## Install Ansible 2.9 Base
#pip3 install ansible==2.9.9
#ansible --version
ansible 2.9.9
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /root/BUGTRIAGE/AnsibleTestEnv/lib/python3.6/site-packages/ansible
  executable location = /root/BUGTRIAGE/AnsibleTestEnv/bin/ansible
  python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]

## Install FortiOS Ansible collection
#ansible-galaxy collection install fortinet.fortios -f

please also make sure your host inventory is correct https://ansible-galaxy-fortios-docs.readthedocs.io/en/latest/playbook.html

thanks,
Link

from ansible-galaxy-fortios-collection.

chillancezen avatar chillancezen commented on July 2, 2024

mark this issue closed.
@forestoden please feel free to reopen it if your issue persists.

thanks,
Link

from ansible-galaxy-fortios-collection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.