I added it. Now this shows:
fatal: [SW1]: FAILED! => {
*"msg": "parse_genie: Genie package is not installed. To install, run
'pip install genie'."*
}
When I do pip or pip3 install genie, it says requirements already satisfied
(as I already installed it).
Just to show you what my directories look like:
[image: directory genie.JPG]
And under [defaults] in my ansible.cfg:
*collections_paths = /etc/ansible/collections/ansible_collections/*
Tried putting a less specific and then a more specifc path to the
collections folder also. (= /etc/ansible/collections, =
/etc/ansible/collections/ansible_collections/clay584/genie)
Prior to this, I did a * ansible-galaxy collection install clay584.genie*
to install the collection and it said this:
Installing 'clay584.genie:0.1.11' to
'/root/.ansible/collections/ansible_collections/clay584/genie'
Did I do anything wrong?
On Tuesday, June 23, 2020 at 11:34:31 AM UTC-4, J C wrote:
>
> You need to add a new line under [defaults]
>
> collections_paths = /path/to/collections
>
> On Tue, Jun 23, 2020 at 10:29 AM Jason <[email protected] <javascript:>>
> wrote:
>
>> No I have never used a collection before. So my ansible.cfg is currently
>> to the default
>>
>> On Tuesday, June 23, 2020 at 11:22:11 AM UTC-4, J C wrote:
>>>
>>> Not sure it seems like it is looking for the filter. Have you used a
>>> collection before? Is the collections_path defined in the ansible.cfg?
>>>
>>> On Mon, Jun 22, 2020 at 3:49 PM Jason <[email protected]> wrote:
>>>
>>>> This error shows:
>>>> fatal: [SW1]: FAILED! => {"msg": "template error while templating
>>>> string: no filter named 'clay584.genie.parse_genie'. String: {{
>>>> neighbors['stdout'][0] | clay584.genie.parse_genie(command='show cdp
>>>> neighbors', os='ios') }}"}
>>>>
>>>>
>>>> This is the full playbook I am using:
>>>> ---
>>>> - name: Interface Descrpitions
>>>> hosts: uwioc-switches
>>>> gather_facts: no
>>>> connection: network_cli
>>>> collections:
>>>> - clay584.genie
>>>> vars:
>>>> ansible_python_interpreter: "{{ ansible_playbook_python }}"
>>>> tasks:
>>>> - name: Run show cdp neighbors
>>>> ios_command:
>>>> commands:
>>>> - show cdp neighbors
>>>> register: neighbors
>>>> # Using the Genie Filter Plugin from the Genie Parse Role
>>>> # Set pyats_neighbors as a dictionary
>>>> - name: Set fact with Genie Filter Plugin
>>>> set_fact:
>>>> pyats_neighbors: "{{ neighbors['stdout'][0] |
>>>> clay584.genie.parse_genie(command='show cdp neighbors', os='ios') }}"
>>>>
>>>>
>>>> Tried changing vars to set_facts too, but didn't work.
>>>>
>>>> On Monday, June 22, 2020 at 4:16:54 PM UTC-4, J C wrote:
>>>>>
>>>>> I am using the collection not the role. So it looks like this at the
>>>>> top. Had to add the interpreter variable because Ansible kept using
>>>>> Python
>>>>> 2
>>>>>
>>>>> ---
>>>>> - name: Interface Descrpitions
>>>>> hosts: all
>>>>> gather_facts: no
>>>>> connection: network_cli
>>>>> collections:
>>>>> - clay584.genie
>>>>> vars:
>>>>> ansible_python_interpreter: "{{ ansible_playbook_python }}"
>>>>>
>>>>> On Mon, Jun 22, 2020 at 2:44 PM Jason <[email protected]> wrote:
>>>>>
>>>>>> Thanks alot.
>>>>>>
>>>>>> I have been getting this error for the past few days when trying to
>>>>>> use genie:
>>>>>>
>>>>>> fatal: [SW1]: FAILED! => {
>>>>>> "msg": "template error while templating string: no filter named
>>>>>> 'clay584.genie.parse_genie'. String: {{ neighbors['stdout'][0] |
>>>>>> clay584.genie.parse_genie(command='show cdp neighbors', os='ios') }}"
>>>>>> }
>>>>>>
>>>>>> *This is my playbook (what you sent but I needed to import the role
>>>>>> first):*
>>>>>> - hosts: uwioc-switches
>>>>>> gather_facts: no
>>>>>> tasks:
>>>>>> - name: Import role
>>>>>> include_role:
>>>>>> name: clay584.parse_genie
>>>>>>
>>>>>> - name: Run show cdp neighbors
>>>>>> ios_command:
>>>>>> commands:
>>>>>> - show cdp neighbors
>>>>>> register: neighbors
>>>>>>
>>>>>> # Using the Genie Filter Plugin from the Genie Parse Role
>>>>>> # Set pyats_neighbors as a dictionary
>>>>>> - name: Set fact with Genie
>>>>>> - name: Import role
>>>>>> include_role:
>>>>>> name: clay584.parse_genie
>>>>>>
>>>>>> - name: Run show cdp neighbors
>>>>>> ios_command:
>>>>>> commands:
>>>>>> - show cdp neighbors
>>>>>> register: neighbors
>>>>>>
>>>>>> # Using the Genie Filter Plugin from the Genie Parse Role
>>>>>> # Set pyats_neighbors as a dictionary
>>>>>> - name: Set fact with Genie Filter Plugin
>>>>>> set_fact:
>>>>>> pyats_neighbors: "{{ neighbors['stdout'][0] |
>>>>>> clay584.genie.parse_genie(command='show cdp neighbors', os='ios') }}"
>>>>>>
>>>>>>
>>>>>> - name: Add interface description
>>>>>> ios_interfaces:
>>>>>> config:
>>>>>> - name: "{{ item.value.local_interface }}"
>>>>>> description: "{{ item.value.device_id }} - {{
>>>>>> item.value.port_id }}"
>>>>>> state: merged
>>>>>> loop: "{{ q('dict', pyats_neighbors.index) }}"
>>>>>> when: item.value.port_id is "AIR-AP280"
>>>>>>
>>>>>> My python version is 3.6.8 and Ansible is 2.9.9
>>>>>>
>>>>>> I followed this guide to install the necessary libraries:
>>>>>>
>>>>>> https://developer.cisco.com/codeexchange/github/repo/clay584/parse_genie/
>>>>>>
>>>>>>
>>>>>> The error still persists. Also posted the issue on GitHub. Not sure
>>>>>> if it is bug in the parsing library.
>>>>>>
>>>>>> Any assistance would greatly be appreciated.
>>>>>>
>>>>>> Thanks.
>>>>>>
>>>>>> On Monday, June 22, 2020 at 9:07:18 AM UTC-4, J C wrote:
>>>>>>>
>>>>>>> Something like that I suppose.
>>>>>>>
>>>>>>>
>>>>>>> #Sets a varaiable for cdp neighbor detail
>>>>>>> - name: Run show cdp neighbors command
>>>>>>> ios_command:
>>>>>>> commands:
>>>>>>> - show cdp neighbors detail
>>>>>>> register: neighbors
>>>>>>>
>>>>>>> # Using the Genie Filter Plugin from the Genie Parse Role
>>>>>>> # Set pyats_neighbors as a dictionary
>>>>>>> - name: Set fact with Genie Filter Plugin
>>>>>>> set_fact:
>>>>>>> pyats_neighbors: "
>>>>>>> {{ neighbors['stdout'][0] | clay584.genie.parse_genie(command='show cdp
>>>>>>> neighbors detail', os='ios') }}
>>>>>>> "
>>>>>>> - name: Add interface desription
>>>>>>> ios_interfaces:
>>>>>>> config:
>>>>>>> - name: "{{ item.value.local_interface }}"
>>>>>>> description: "
>>>>>>> {{ item.value.device_id }} - {{ item.value.port_id }}"
>>>>>>> state: merged
>>>>>>> loop: "{{ q('dict', pyats_neighbors.index) }}"
>>>>>>> when: item.value.port_id is "AIR-AP280"
>>>>>>>
>>>>>>> On Sat, Jun 20, 2020 at 1:34 PM Jason <[email protected]> wrote:
>>>>>>>
>>>>>>>> Thanks. If you don't mind me asking because I am not familiar with
>>>>>>>> this, can you give me an example of how to use the set fact and when
>>>>>>>> statement for my case?
>>>>>>>>
>>>>>>>> On Friday, June 19, 2020 at 11:22:31 PM UTC-4, J C wrote:
>>>>>>>>>
>>>>>>>>> I would use the genie module and run the show cdp neighbor
>>>>>>>>> command. Then set fact and use that with the when command.
>>>>>>>>>
>>>>>>>>> On Fri, Jun 19, 2020, 10:05 PM Jason <[email protected]> wrote:
>>>>>>>>>
>>>>>>>>>> I am working on a project that would require me to bump (shutdown
>>>>>>>>>> and re-enable) switchports that are connected to an Access Point.
>>>>>>>>>>
>>>>>>>>>> I have created a playbook to run a command "show cdp neighbours"
>>>>>>>>>> on the switch, and that output would look like:
>>>>>>>>>> [image: sh cdp neighbours.JPG]
>>>>>>>>>>
>>>>>>>>>> What I want to do, is to use ansible to only run a command
>>>>>>>>>> (ansible play) on Gig 1/0/19 in this case. For other switches, it
>>>>>>>>>> may be
>>>>>>>>>> more switchports and maybe in different format (eg. Gi 2/0/35).
>>>>>>>>>>
>>>>>>>>>> Is there a way to filter ansible output by looking for
>>>>>>>>>> 'AIR-AP280' and then extract that corresponding Local Interface
>>>>>>>>>> (switchport
>>>>>>>>>> number)?
>>>>>>>>>>
>>>>>>>>>> Or if there is another way to get done what I want, then great.
>>>>>>>>>>
>>>>>>>>>> Any suggestions/recommendations?
>>>>>>>>>>
>>>>>>>>>> It is over 50 switches, so it would be great if ansible can do
>>>>>>>>>> what I want to do.
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> You received this message because you are subscribed to the
>>>>>>>>>> Google Groups "Ansible Project" group.
>>>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>>>> send an email to [email protected].
>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>> https://groups.google.com/d/msgid/ansible-project/fd4b0f7a-85ba-4921-b252-9b760d1bd3d8o%40googlegroups.com
>>>>>>>>>>
>>>>>>>>>> <https://groups.google.com/d/msgid/ansible-project/fd4b0f7a-85ba-4921-b252-9b760d1bd3d8o%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>>> .
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>> You received this message because you are subscribed to the Google
>>>>>>>> Groups "Ansible Project" group.
>>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>>> send an email to [email protected].
>>>>>>>> To view this discussion on the web visit
>>>>>>>> https://groups.google.com/d/msgid/ansible-project/644c6f2a-5a02-49fd-b84a-1c74ad722daao%40googlegroups.com
>>>>>>>>
>>>>>>>> <https://groups.google.com/d/msgid/ansible-project/644c6f2a-5a02-49fd-b84a-1c74ad722daao%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>> .
>>>>>>>>
>>>>>>> --
>>>>>> You received this message because you are subscribed to the Google
>>>>>> Groups "Ansible Project" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>> send an email to [email protected].
>>>>>> To view this discussion on the web visit
>>>>>> https://groups.google.com/d/msgid/ansible-project/9a09ee0c-1184-4d74-a41f-b69a89fca04co%40googlegroups.com
>>>>>>
>>>>>> <https://groups.google.com/d/msgid/ansible-project/9a09ee0c-1184-4d74-a41f-b69a89fca04co%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>>
>>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Ansible Project" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/ansible-project/36cda932-fe68-499b-a70b-acf81cd693cfo%40googlegroups.com
>>>>
>>>> <https://groups.google.com/d/msgid/ansible-project/36cda932-fe68-499b-a70b-acf81cd693cfo%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/cda449ee-3155-40ab-9feb-474d1355bf8eo%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/cda449ee-3155-40ab-9feb-474d1355bf8eo%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/cb187525-7951-44d3-b7d5-3dfb704b1ffco%40googlegroups.com.