Automation

 View Only
last person joined: 10 days ago 

Ask questions and share experiences about Apstra, Paragon, and all things network automation.
  • 1.  Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

    Posted 04-05-2024 14:42

    Hello,

    My environment details: 

    Windows11-wsl2: Ubuntu 20.04, Virtual environment: python3.8-full, within virtual env: Installed Ansible, Junos-pyez, Jxmlease, xmltodict. 

    I am able to NETCONF to lab device from Juniper vlab but getting error message for second task for making configuration changes.

    (myansible) student@DESKTOP-VF2VLG4:~$ ansible-playbook -i configuration/hosts Interface_desc_update.yml
     
    PLAY [Load and commit Junos configurations] ****************************************************************************************************************
     
    TASK [Verify NETCONF connectivity] *************************************************************************************************************************
    ok: [66.129.234.215]
     
    TASK [Load and commit the configurations] ******************************************************************************************************************
    An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'jnpr'
    fatal: [66.129.234.215]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/home/student/.ansible/tmp/ansible-tmp-1712339458.1710489-1769-257087027421743/AnsiballZ_config.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/home/student/.ansible/tmp/ansible-tmp-1712339458.1710489-1769-257087027421743/AnsiballZ_config.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/student/.ansible/tmp/ansible-tmp-1712339458.1710489-1769-257087027421743/AnsiballZ_config.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.config', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.config', _modlib_path=modlib_path),\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_juniper.device.config_payload_vpwou34_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/modules/config.py\", line 828, in <module>\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/tmp/ansible_juniper.device.config_payload_vpwou34_/ansible_juniper.device.config_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 42, in <module>\nModuleNotFoundError: No module named 'jnpr'\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
     
    PLAY RECAP *************************************************************************************************************************************************
    66.129.234.215             : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
     
    (myansible) student@DESKTOP-VF2VLG4:~$ python3
    Python 3.8.10 (default, Nov 22 2023, 10:22:35)
    [GCC 9.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import jnpr.junos
    >>> jnpr.junos.__version__
    '2.7.0'
    >>>

    Thank you in advance for sparing time to look into this.

    Thanks

    Amrish



    ------------------------------
    AMRISH PATEL
    ------------------------------


  • 2.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

     
    Posted 04-08-2024 04:15

    Please share your playbook.  Thanks.



    ------------------------------
    Andy Sharp
    ------------------------------



  • 3.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

    Posted 04-08-2024 13:23

    Thanks for looking into this Andy!

    Playbook:

    student@DESKTOP-VF2VLG4:~$ more Interface_desc_update.yml
    - name: Load and commit Junos configurations
      hosts: core
      connection: local
      gather_facts: no
     
      tasks:
        - name: Verify NETCONF connectivity
          wait_for:
           host: "{{ inventory_hostname }}"
           port: 32006
           timeout: 5
     
        - name: Load and commit the configurations
          juniper.device.config:
            load: "override"
            timeout: 20
            src: "configuration/vmx02/vmx02_cfg.txt"
            comment: "Load the interface description configuration on the vlab devices"
    student@DESKTOP-VF2VLG4:~$
    Thanks
    Amrish Patel


    ------------------------------
    AMRISH PATEL
    ------------------------------



  • 4.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

     
    Posted 04-09-2024 04:27

    I saw no reference in your playbook to the collection that you are using.

    I've not looked further than this to see if there are any other issues, but in the first instance, see if you get further once adding the collection to your playbook.  If you still get issues, provide an update, and I'll find some time to look more deeply.

    Regards

    - name: Load and commit Junos configurations
      hosts: core
      collections:
        - juniper.device
      connection: local
      gather_facts: no
     
      tasks:
        - name: Verify NETCONF connectivity
          wait_for:
           host: "{{ inventory_hostname }}"
           port: 32006
           timeout: 5
     
        - name: Load and commit the configurations
          juniper.device.config:
            load: "override"
            timeout: 20
            src: "configuration/vmx02/vmx02_cfg.txt"
            comment: "Load the interface description configuration on the vlab devices"


    ------------------------------
    Andy Sharp
    ------------------------------



  • 5.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

    Posted 25 days ago

    Hi Andy, 

    I'm running into the same issue and applied the fix you suggested, but still recieving the same error. Not sure what I'm missing here. Thoughts? 

    Error

    The full traceback is:
    Traceback (most recent call last):
      File "/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.245114-38020-219984360650332/AnsiballZ_facts.py", line 107, in <module>
        _ansiballz_main()
      File "/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.245114-38020-219984360650332/AnsiballZ_facts.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.245114-38020-219984360650332/AnsiballZ_facts.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.facts', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.facts', _modlib_path=modlib_path),
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_79iopvgz/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/modules/facts.py", line 191, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_79iopvgz/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 42, in <module>
    ModuleNotFoundError: No module named 'jnpr'
    fatal: [rtr2-lab.net]: FAILED! => {
        "changed": false,
        "module_stderr": "Traceback (most recent call last):\n  File \"/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.245114-38020-219984360650332/AnsiballZ_facts.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.245114-38020-219984360650332/AnsiballZ_facts.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.245114-38020-219984360650332/AnsiballZ_facts.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.facts', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.facts', _modlib_path=modlib_path),\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_79iopvgz/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/modules/facts.py\", line 191, in <module>\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_79iopvgz/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 42, in <module>\nModuleNotFoundError: No module named 'jnpr'\n",
        "module_stdout": "",
        "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
        "rc": 1
    }
    The full traceback is:
    Traceback (most recent call last):
      File "/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.2434409-38019-6165087115636/AnsiballZ_facts.py", line 107, in <module>
        _ansiballz_main()
      File "/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.2434409-38019-6165087115636/AnsiballZ_facts.py", line 99, in _ansiballz_main
        invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
      File "/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.2434409-38019-6165087115636/AnsiballZ_facts.py", line 47, in invoke_module
        runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.facts', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.facts', _modlib_path=modlib_path),
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
        return _run_module_code(code, init_globals, run_name, mod_spec)
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
        _run_code(code, mod_globals, init_globals,
      File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_3_7n_xa6/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/modules/facts.py", line 191, in <module>
      File "<frozen zipimport>", line 259, in load_module
      File "/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_3_7n_xa6/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py", line 42, in <module>
    ModuleNotFoundError: No module named 'jnpr'
    fatal: [rtr1-lab.net]: FAILED! => {
        "changed": false,
        "module_stderr": "Traceback (most recent call last):\n  File \"/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.2434409-38019-6165087115636/AnsiballZ_facts.py\", line 107, in <module>\n    _ansiballz_main()\n  File \"/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.2434409-38019-6165087115636/AnsiballZ_facts.py\", line 99, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/leonardo.uribe/.ansible/tmp/ansible-tmp-1719617245.2434409-38019-6165087115636/AnsiballZ_facts.py\", line 47, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.juniper.device.plugins.modules.facts', init_globals=dict(_module_fqn='ansible_collections.juniper.device.plugins.modules.facts', _modlib_path=modlib_path),\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_3_7n_xa6/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/modules/facts.py\", line 191, in <module>\n  File \"<frozen zipimport>\", line 259, in load_module\n  File \"/var/folders/0y/b0gm81gx14n1y5gx0rjpxw1h0000gn/T/ansible_juniper.device.facts_payload_3_7n_xa6/ansible_juniper.device.facts_payload.zip/ansible_collections/juniper/device/plugins/module_utils/juniper_junos_common.py\", line 42, in <module>\nModuleNotFoundError: No module named 'jnpr'\n",
        "module_stdout": "",
        "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
        "rc": 1
    }
    
    PLAY RECAP ************************************************************************************************************************************************************************************************************************************************************************
    rtr1-lab.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   
    rtr2-lab.net : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

    Playbook

    ---
    - name: Test
      hosts: rtrs_lab
      connection: local
      gather_facts: false
      collections:
        - juniper.device
      vars_prompt:
        - name: USERNAME
          prompt: User name
          private: false
        - name: DEVICE_PASSWORD
          prompt: Device password
          private: true
      tasks:
        - name: Get Junos device information
          juniper.device.facts:
            user: "{{ USERNAME }}"
            passwd: "{{ DEVICE_PASSWORD }}"
          register: junos_facts
        - name: Print Junos facts
          ansible.builtin.debug:
            msg: "{{ junos_facts }}"

    thanks,

    Leo



    ------------------------------
    LEONARDO URIBE
    ------------------------------



  • 6.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

     
    Posted 25 days ago

    Which Python interpreter is Ansible using in your setup?

    You can find this out by executing ansible --version

    e.g.

    ansible --version | grep "python version"
      python version = 3.9.6 (default, Feb  3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)] (/Library/Developer/CommandLineTools/usr/bin/python3)
    
    or
    ansible --version
    ansible [core 2.15.12]
      config file = None
      configured module search path = ['/Users/asharp/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /Users/asharp/Library/Python/3.9/lib/python/site-packages/ansible
      ansible collection location = /Users/asharp/.ansible/collections:/usr/share/ansible/collections
      executable location = /Users/asharp/Library/Python/3.9/bin/ansible
      python version = 3.9.6 (default, Feb  3 2024, 15:58:27) [Clang 15.0.0 (clang-1500.3.9.4)] (/Library/Developer/CommandLineTools/usr/bin/python3)
      jinja version = 3.1.2
      libyaml = True
    

    Then can you check if junos-eznc is installed against that version of Ansible.  e.g.

    /Library/Developer/CommandLineTools/usr/bin/python3 -m pip freeze | grep junos
    junos-eznc==2.7.1

    Regards,

    Andy



    ------------------------------
    Andy Sharp
    ------------------------------



  • 7.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

    Posted 25 days ago

    Ansible is using Python version 3.12.3

    ansible --version | grep "python version"
      python version = 3.12.3 (v3.12.3:f6650f9ad7, Apr  9 2024, 08:18:47) [Clang 13.0.0 (clang-1300.0.29.30)] (/Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12)
    


    The junos-eznc is installed. 

    pip3 freeze | grep junos     
    junos-eznc==2.7.1

    thanks,

    Leo



    ------------------------------
    LEONARDO URIBE
    ------------------------------



  • 8.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

     
    Posted 25 days ago
    Edited by Juniper Community Admin 25 days ago

    Please provide the output from the following command:

    /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12 -m pip freeze | grep junos


    I suspect that you have multiple installations of Python3 on your system, one has jnpr-pyez installed, however the version that Ansible is using doesn't.

    For example, take the following 2 examples:

    The first here, is the version of Python that my installation of Ansible is using.  This is the version against which I have installed jnpr-pyez.  I can verify that by running that version of Python and I am able to include jnpr.junos.
    
    /Library/Developer/CommandLineTools/usr/bin/python3
    Python 3.9.6 (default, Feb  3 2024, 15:58:27)
    [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from jnpr.junos import Device
    >>> dir(Device)
    ['ON_JUNOS', 'Template', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_rpc_reply', '_sshconf_lkup', '_sshconf_path', 'auto_probe', 'bind', 'cli', 'cli_to_rpc_string', 'close', 'connected', 'display_xml_rpc', 'execute', 'facts_refresh', 'hostname', 'logfile', 'manages', 'master', 'ofacts', 'open', 'password', 'port', 'probe', 're_name', 'timeout', 'transform', 'uptime', 'user']
    
    Now, if I use my default Python3 installation, I know that I do not have PyEz installed for it.
    which python3
    /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
    
    /Library/Frameworks/Python.framework/Versions/3.12/bin/python3
    Python 3.12.0 (v3.12.0:0fb18b02c8, Oct  2 2023, 09:45:56) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from jnpr.junos import Device
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'jnpr'
    >>>

    I suspect that the situation is in reverse for yourself.  Which is your default Python3 (which python3) has junos-pyez installed against it, however Ansible is looking to use a different interpreter and PyEz isn't installed for use with that one.

    You might be able to point Ansible to use a different interpreter  reference: https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html#interpreter-discovery

    Or install PyEz against that particular instance of Python that Ansible is using.

    Regards,


    ------------------------------
    Andy Sharp
    ------------------------------



  • 9.  RE: Ansible playbook error: ModuleNotFoundError: No module named 'jnpr'

    Posted 24 days ago

    Did some digging and found that the issue was with the interpreter VSCode was using. Once I changed the interpreter and ensured all of the packages were installed against it, I was able to run my playbook. Thanks for the quick and details responses Andy! 



    ------------------------------
    LEONARDO URIBE
    ------------------------------