Unable to run play using Galaxy role Genie

  • Set at least one tag (the experts follow the tags, so the right people will find you if you tag)

I am working through a Automating Networks with Ansible course on CBT Nuggets. In the section going through Ansible-Galaxy we install Genie and are supposed to parse some data. Iv followed the video exactly and ran the same commands and created the same playbook but when I run it I keep getting the following error.

fatal: [10.0.15.7]: FAILED! => {"msg": "parse_genie: Genie package is not installed. To install, run 'pip install genie'."}

Directory Tree:

(.venv) [bmarr@localhost CBT-Automating-Networks-with-Ansible]$ tree
.
β”œβ”€β”€ accessvars.yml
β”œβ”€β”€ ansible.cfg
β”œβ”€β”€ bannerconf.yml
β”œβ”€β”€ cisco_default_configuration
β”‚   β”œβ”€β”€ banner_exec.cfg
β”‚   └── banner_login.cfg
β”œβ”€β”€ condition_test.yml
β”œβ”€β”€ eigrp
β”‚   β”œβ”€β”€ legacy.j2
β”‚   └── named.j2
β”œβ”€β”€ encrypt-test.yml
β”œβ”€β”€ genie_parse_playbook.yml
β”œβ”€β”€ group_vars
β”‚   β”œβ”€β”€ all.yml
β”‚   β”œβ”€β”€ uk.yml
β”‚   └── usa.yml
β”œβ”€β”€ handler-example.yml
β”œβ”€β”€ hosts
β”œβ”€β”€ host_vars
β”‚   β”œβ”€β”€ 10.0.15.13.yml
β”‚   β”œβ”€β”€ 10.0.15.14.yml
β”‚   └── 10.0.15.7.yml
β”œβ”€β”€ ip-filter-test.yml
β”œβ”€β”€ loop-ip-address.yml
β”œβ”€β”€ newtest.yml
β”œβ”€β”€ ntp_config.yml
β”œβ”€β”€ nuggets
β”‚   β”œβ”€β”€ defaults
β”‚   β”‚   └── main.yml
β”‚   β”œβ”€β”€ handlers
β”‚   β”‚   └── main.yml
β”‚   β”œβ”€β”€ meta
β”‚   β”‚   └── main.yml
β”‚   β”œβ”€β”€ README.md
β”‚   β”œβ”€β”€ tasks
β”‚   β”‚   └── main.yml
β”‚   β”œβ”€β”€ tests
β”‚   β”‚   β”œβ”€β”€ inventory
β”‚   β”‚   └── test.yml
β”‚   └── vars
β”‚       └── main.yml
β”œβ”€β”€ play.yml
β”œβ”€β”€ printvars.yml
β”œβ”€β”€ register-example.yml
β”œβ”€β”€ templates
β”‚   β”œβ”€β”€ bgp.j2
β”‚   └── ntp.j2
└── var_example1.yml


12 directories, 36 files

Steps taken to install …

  1. install clay584.genie galaxy collection
    [bmarr@localhost ~]$ ansible-galaxy collection install clay584.genie
  2. create venv and activate then install pyats
[bmarr@localhost ~]$ python3 -m venv .venv
[bmarr@localhost ~]$ cd .venv/
[bmarr@localhost .venv]$ source bin/activate
(.venv) [bmarr@localhost .venv]$ cd ..
  1. install pyats
    (.venv) [bmarr@localhost ~]$ pip install pyats
  2. install genie
    (.venv) [bmarr@localhost ~]$ pip install genie
  3. back to the folder where my ansible playbooks are at and run the play
    (.venv) [bmarr@localhost ~]$ cd CBT-Automating-Networks-with-Ansible/
    (.venv) [bmarr@localhost CBT-Automating-Networks-with-Ansible]$ ansible-playbook genie_parse_playbook.yml -vvvvv

=

=

FILES:


ansible.cfg

[defaults]
gathering = explicit
inventory = ./hosts
host_key_checking=False
deprecation_warnings=False
interpreter_python=/usr/local/bin/python3

genie_parse_playbook.yml

---

- name: playbook 1 testing genie
  hosts: 10.0.15.7
  connection: network_cli

  tasks:
    - name: task 1 send a show command
      cisco.ios.ios_command:
        commands: show version
      register: show_version_output

    - name: task 2 parse show command
      set_fact:
        parsed_data: >-
          {{ show_version_output.stdout.0 | clay584.genie.parse_genie(
            command='show version', os='ios'
          ) }}
        
    - name: task 3 print output
      debug:
        msg: "{{ parsed_data }}"

=

=

Play output: Error on TASK [task 2 parse show command] at the end of the play

ansible-playbook [core 2.15.13]
  config file = /home/bmarr/CBT-Automating-Networks-with-Ansible/ansible.cfg
  configured module search path = ['/home/bmarr/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/bmarr/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/bmarr/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/bmarr/.local/bin/ansible-playbook
  python version = 3.9.21 (main, Dec  5 2024, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-2)] (/usr/bin/python3)
  jinja version = 3.1.5
  libyaml = True
Using /home/bmarr/CBT-Automating-Networks-with-Ansible/ansible.cfg as config file
setting up inventory plugins
Loading collection ansible.builtin from 
host_list declined parsing /home/bmarr/CBT-Automating-Networks-with-Ansible/hosts as it did not pass its verify_file() method
script declined parsing /home/bmarr/CBT-Automating-Networks-with-Ansible/hosts as it did not pass its verify_file() method
auto declined parsing /home/bmarr/CBT-Automating-Networks-with-Ansible/hosts as it did not pass its verify_file() method
Parsed /home/bmarr/CBT-Automating-Networks-with-Ansible/hosts inventory source with ini plugin
Loading collection cisco.ios from /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/cisco/ios
redirecting (type: action) cisco.ios.ios_command to cisco.ios.ios
Loading callback plugin default of type stdout, v2.0 from /home/bmarr/.local/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Attempting to use 'default' callback.
Skipping callback 'default', as we already have a stdout callback.
Attempting to use 'junit' callback.
Attempting to use 'minimal' callback.
Skipping callback 'minimal', as we already have a stdout callback.
Attempting to use 'oneline' callback.
Skipping callback 'oneline', as we already have a stdout callback.
Attempting to use 'tree' callback.

PLAYBOOK: genie_parse_playbook.yml ******************************************************************************************************************************************************************
Positional arguments: genie_parse_playbook.yml
verbosity: 5
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/home/bmarr/CBT-Automating-Networks-with-Ansible/hosts',)
forks: 5
1 plays in genie_parse_playbook.yml

PLAY [playbook 1 testing genie] *********************************************************************************************************************************************************************
redirecting (type: action) cisco.ios.ios_command to cisco.ios.ios
Loading collection ansible.netcommon from /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/ansible/netcommon

TASK [task 1 send a show command] *******************************************************************************************************************************************************************
task path: /home/bmarr/CBT-Automating-Networks-with-Ansible/genie_parse_playbook.yml:8
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
Loading collection ansible.utils from /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/ansible/utils
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<10.0.15.7> attempting to start connection
<10.0.15.7> using connection plugin ansible.netcommon.network_cli
Found ansible-connection at path /home/bmarr/.local/bin/ansible-connection
<10.0.15.7> local domain socket does not exist, starting it
<10.0.15.7> control socket path is /home/bmarr/.ansible/pc/9c4b65f273
<10.0.15.7> Loading collection ansible.builtin from 
<10.0.15.7> redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
<10.0.15.7> Loading collection ansible.netcommon from /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/ansible/netcommon
<10.0.15.7> Loading collection ansible.utils from /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/ansible/utils
<10.0.15.7> redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
<10.0.15.7> Loading collection cisco.ios from /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/cisco/ios
<10.0.15.7> redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
<10.0.15.7> local domain socket listeners started successfully
<10.0.15.7> loaded cliconf plugin ansible_collections.cisco.ios.plugins.cliconf.ios from path /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/cisco/ios/plugins/cliconf/ios.py for network_os ios
<10.0.15.7> ssh type is set to auto
<10.0.15.7> autodetecting ssh_type
<10.0.15.7> ssh type is now set to libssh
<10.0.15.7> Loading collection ansible.builtin from 
<10.0.15.7> local domain socket path is /home/bmarr/.ansible/pc/9c4b65f273
redirecting (type: action) cisco.ios.ios_command to cisco.ios.ios
redirecting (type: action) cisco.ios.ios_command to cisco.ios.ios
<10.0.15.7> ANSIBLE_NETWORK_IMPORT_MODULES: enabled
<10.0.15.7> ANSIBLE_NETWORK_IMPORT_MODULES: found cisco.ios.ios_command  at /home/bmarr/.local/lib/python3.9/site-packages/ansible_collections/cisco/ios/plugins/modules/ios_command.py
<10.0.15.7> ANSIBLE_NETWORK_IMPORT_MODULES: running cisco.ios.ios_command
<10.0.15.7> ANSIBLE_NETWORK_IMPORT_MODULES: complete
<10.0.15.7> ANSIBLE_NETWORK_IMPORT_MODULES: Result: {'changed': False, 'stdout': ['Cisco IOS XE Software, Version 17.03.08a\nCisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.8a, RELEASE SOFTWARE (fc3)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2023 by Cisco Systems, Inc.\nCompiled Fri 20-Oct-23 15:48 by mcpre\n\n\nCisco IOS-XE software, Copyright (c) 2005-2023 by cisco Systems, Inc.\nAll rights reserved.  Certain components of Cisco IOS-XE software are\nlicensed under the GNU General Public License ("GPL") Version 2.0.  The\nsoftware code licensed under GPL Version 2.0 is free software that comes\nwith ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such\nGPL code under the terms of GPL Version 2.0.  For more details, see the\ndocumentation or "License Notice" file accompanying the IOS-XE software,\nor the applicable URL provided on the flyer accompanying the IOS-XE\nsoftware.\n\n\nROM: IOS-XE ROMMON\n\nR1 uptime is 3 hours, 32 minutes\nUptime for this control processor is 3 hours, 34 minutes\nSystem returned to ROM by reload at 02:17:08 UTC Sun Feb 2 2025\nSystem image file is "bootflash:packages.conf"\nLast reload reason: Reload Command\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\nLicense Level: ax\nLicense Type: N/A(Smart License Enabled)\nNext reload license Level: ax\n\nThe current throughput level is 1000 kbps \n\n\nSmart Licensing Status: UNREGISTERED/No Licenses in Use\n\ncisco CSR1000V (VXE) processor (revision VXE) with 2070552K/3075K bytes of memory.\nProcessor board ID 9QQ3Y05ZEFO\nRouter operating mode: Autonomous\n4 Gigabit Ethernet interfaces\n32768K bytes of non-volatile configuration memory.\n3978232K bytes of physical memory.\n6188032K bytes of virtual hard disk at bootflash:.\n\nConfiguration register is 0x2102'], 'stdout_lines': [['Cisco IOS XE Software, Version 17.03.08a', 'Cisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.8a, RELEASE SOFTWARE (fc3)', 'Technical Support: http://www.cisco.com/techsupport', 'Copyright (c) 1986-2023 by Cisco Systems, Inc.', 'Compiled Fri 20-Oct-23 15:48 by mcpre', '', '', 'Cisco IOS-XE software, Copyright (c) 2005-2023 by cisco Systems, Inc.', 'All rights reserved.  Certain components of Cisco IOS-XE software are', 'licensed under the GNU General Public License ("GPL") Version 2.0.  The', 'software code licensed under GPL Version 2.0 is free software that comes', 'with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such', 'GPL code under the terms of GPL Version 2.0.  For more details, see the', 'documentation or "License Notice" file accompanying the IOS-XE software,', 'or the applicable URL provided on the flyer accompanying the IOS-XE', 'software.', '', '', 'ROM: IOS-XE ROMMON', '', 'R1 uptime is 3 hours, 32 minutes', 'Uptime for this control processor is 3 hours, 34 minutes', 'System returned to ROM by reload at 02:17:08 UTC Sun Feb 2 2025', 'System image file is "bootflash:packages.conf"', 'Last reload reason: Reload Command', '', '', '', 'This product contains cryptographic features and is subject to United', 'States and local country laws governing import, export, transfer and', 'use. Delivery of Cisco cryptographic products does not imply', 'third-party authority to import, export, distribute or use encryption.', 'Importers, exporters, distributors and users are responsible for', 'compliance with U.S. and local country laws. By using this product you', 'agree to comply with applicable laws and regulations. If you are unable', 'to comply with U.S. and local laws, return this product immediately.', '', 'A summary of U.S. laws governing Cisco cryptographic products may be found at:', 'http://www.cisco.com/wwl/export/crypto/tool/stqrg.html', '', 'If you require further assistance please contact us by sending email to', 'export@cisco.com.', '', 'License Level: ax', 'License Type: N/A(Smart License Enabled)', 'Next reload license Level: ax', '', 'The current throughput level is 1000 kbps ', '', '', 'Smart Licensing Status: UNREGISTERED/No Licenses in Use', '', 'cisco CSR1000V (VXE) processor (revision VXE) with 2070552K/3075K bytes of memory.', 'Processor board ID 9QQ3Y05ZEFO', 'Router operating mode: Autonomous', '4 Gigabit Ethernet interfaces', '32768K bytes of non-volatile configuration memory.', '3978232K bytes of physical memory.', '6188032K bytes of virtual hard disk at bootflash:.', '', 'Configuration register is 0x2102']], 'invocation': {'module_args': {'commands': ['show version'], 'match': 'all', 'retries': 9, 'interval': 1, 'wait_for': None}}, '_ansible_parsed': True}
ok: [10.0.15.7] => {
    "changed": false,
    "invocation": {
        "module_args": {
            "commands": [
                "show version"
            ],
            "interval": 1,
            "match": "all",
            "retries": 9,
            "wait_for": null
        }
    },
    "stdout": [
        "Cisco IOS XE Software, Version 17.03.08a\nCisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.8a, RELEASE SOFTWARE (fc3)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2023 by Cisco Systems, Inc.\nCompiled Fri 20-Oct-23 15:48 by mcpre\n\n\nCisco IOS-XE software, Copyright (c) 2005-2023 by cisco Systems, Inc.\nAll rights reserved.  Certain components of Cisco IOS-XE software are\nlicensed under the GNU General Public License (\"GPL\") Version 2.0.  The\nsoftware code licensed under GPL Version 2.0 is free software that comes\nwith ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such\nGPL code under the terms of GPL Version 2.0.  For more details, see the\ndocumentation or \"License Notice\" file accompanying the IOS-XE software,\nor the applicable URL provided on the flyer accompanying the IOS-XE\nsoftware.\n\n\nROM: IOS-XE ROMMON\n\nR1 uptime is 3 hours, 32 minutes\nUptime for this control processor is 3 hours, 34 minutes\nSystem returned to ROM by reload at 02:17:08 UTC Sun Feb 2 2025\nSystem image file is \"bootflash:packages.conf\"\nLast reload reason: Reload Command\n\n\n\nThis product contains cryptographic features and is subject to United\nStates and local country laws governing import, export, transfer and\nuse. Delivery of Cisco cryptographic products does not imply\nthird-party authority to import, export, distribute or use encryption.\nImporters, exporters, distributors and users are responsible for\ncompliance with U.S. and local country laws. By using this product you\nagree to comply with applicable laws and regulations. If you are unable\nto comply with U.S. and local laws, return this product immediately.\n\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\n\nIf you require further assistance please contact us by sending email to\nexport@cisco.com.\n\nLicense Level: ax\nLicense Type: N/A(Smart License Enabled)\nNext reload license Level: ax\n\nThe current throughput level is 1000 kbps \n\n\nSmart Licensing Status: UNREGISTERED/No Licenses in Use\n\ncisco CSR1000V (VXE) processor (revision VXE) with 2070552K/3075K bytes of memory.\nProcessor board ID 9QQ3Y05ZEFO\nRouter operating mode: Autonomous\n4 Gigabit Ethernet interfaces\n32768K bytes of non-volatile configuration memory.\n3978232K bytes of physical memory.\n6188032K bytes of virtual hard disk at bootflash:.\n\nConfiguration register is 0x2102"
    ],
    "stdout_lines": [
        [
            "Cisco IOS XE Software, Version 17.03.08a",
            "Cisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.8a, RELEASE SOFTWARE (fc3)",
            "Technical Support: http://www.cisco.com/techsupport",
            "Copyright (c) 1986-2023 by Cisco Systems, Inc.",
            "Compiled Fri 20-Oct-23 15:48 by mcpre",
            "",
            "",
            "Cisco IOS-XE software, Copyright (c) 2005-2023 by cisco Systems, Inc.",
            "All rights reserved.  Certain components of Cisco IOS-XE software are",
            "licensed under the GNU General Public License (\"GPL\") Version 2.0.  The",
            "software code licensed under GPL Version 2.0 is free software that comes",
            "with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such",
            "GPL code under the terms of GPL Version 2.0.  For more details, see the",
            "documentation or \"License Notice\" file accompanying the IOS-XE software,",
            "or the applicable URL provided on the flyer accompanying the IOS-XE",
            "software.",
            "",
            "",
            "ROM: IOS-XE ROMMON",
            "",
            "R1 uptime is 3 hours, 32 minutes",
            "Uptime for this control processor is 3 hours, 34 minutes",
            "System returned to ROM by reload at 02:17:08 UTC Sun Feb 2 2025",
            "System image file is \"bootflash:packages.conf\"",
            "Last reload reason: Reload Command",
            "",
            "",
            "",
            "This product contains cryptographic features and is subject to United",
            "States and local country laws governing import, export, transfer and",
            "use. Delivery of Cisco cryptographic products does not imply",
            "third-party authority to import, export, distribute or use encryption.",
            "Importers, exporters, distributors and users are responsible for",
            "compliance with U.S. and local country laws. By using this product you",
            "agree to comply with applicable laws and regulations. If you are unable",
            "to comply with U.S. and local laws, return this product immediately.",
            "",
            "A summary of U.S. laws governing Cisco cryptographic products may be found at:",
            "http://www.cisco.com/wwl/export/crypto/tool/stqrg.html",
            "",
            "If you require further assistance please contact us by sending email to",
            "export@cisco.com.",
            "",
            "License Level: ax",
            "License Type: N/A(Smart License Enabled)",
            "Next reload license Level: ax",
            "",
            "The current throughput level is 1000 kbps ",
            "",
            "",
            "Smart Licensing Status: UNREGISTERED/No Licenses in Use",
            "",
            "cisco CSR1000V (VXE) processor (revision VXE) with 2070552K/3075K bytes of memory.",
            "Processor board ID 9QQ3Y05ZEFO",
            "Router operating mode: Autonomous",
            "4 Gigabit Ethernet interfaces",
            "32768K bytes of non-volatile configuration memory.",
            "3978232K bytes of physical memory.",
            "6188032K bytes of virtual hard disk at bootflash:.",
            "",
            "Configuration register is 0x2102"
        ]
    ]
}

TASK [task 2 parse show command] ********************************************************************************************************************************************************************
task path: /home/bmarr/CBT-Automating-Networks-with-Ansible/genie_parse_playbook.yml:13
Loading collection clay584.genie from /home/bmarr/.ansible/collections/ansible_collections/clay584/genie
fatal: [10.0.15.7]: FAILED! => {
    "msg": "parse_genie: Genie package is not installed. To install, run 'pip install genie'."
}

PLAY RECAP ******************************************************************************************************************************************************************************************
10.0.15.7                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Hi there,

Are you running Ansible installed from the same venv? If you’re using the OS packages for Ansible that python environment doesn’t have the required packages available.

IIRC, you could still use the OS package for Ansible and install packages with pip as a user.

So from what i gathered from your feedback here is that I didnt have ansible installed within the venv, so i installed ansible under the venv and re-ran the playbook with success.

(.venv) [bmarr@localhost .venv]$ pip install ansible

as for the other part

Im still pretty fresh in linux and ansible, what are you meaning by this? Is it possible to install the packages within the venv and they are useable while not in the venv?
3. install pyats
(.venv) [bmarr@localhost ~]$ pip install pyats
4. install genie
(.venv) [bmarr@localhost ~]$ pip install genie

I would like to not have to enter a venv everytime i want to use the galaxy collection, per the video course they stated it could cause problems if the galaxy packages are installed outside of the venv. If this is not possible then thats fine ill make due but im hoping thats not the case.

OR

Should i have just created a venv for Ansible from the start and only work in the venv when using ansible?

Well, in a nutshell, there’s multiple ways of running Python software:

  • As β€˜system’ (apt install python-package python-module or pip install package): you can run these as any use on the system
  • As β€˜user’ (pip --user install package): uses the system libraries above, enriched with the libraries installed in your homedirectory
  • As β€˜venv’: the one you use now: an isolated environment that overrides any and all system/user packages. You can even run different versions of the same package in different venvs if you want (useful when troubleshooting or developing!)

So, you have some options, either install all packages in the system/user session, or set up the venv with all software you need. It depends on your sitation, but there can be benefits to using venvs, as you can generally install anything you want (with pip or otherwise) and not scew up your system’s libraries.

And you should probably look into pipx as well, this is a tool that sets up a venv in a transparant manner (as in pipx install ansible-core and you can just run the ansible command without entering the venv).

More deets β†’ Getting Started - pipx

2 Likes

I tried using the pipx method and couldnt run ther play

pipx install pyats
pipx install genie

i then tried using the --user method and this worked out for me.
pip install pyats genie --user

Thanks for the breakdown of the different install methods.

Good that you managed to make it work! For pipx, if you want to add extra libraries to an existing venv with a command (ansible in this case), you can use pipx inject to add extra python packages to it. It sounds to me that might fix your problem