Git Product home page Git Product logo

Comments (9)

GGabriele avatar GGabriele commented on August 30, 2024

Hi @lmshippy ,
that's because the module only supports a limited amount of commands and show run X is not one of them.

You can take a look at all the supported commands here

from ntc-ansible.

lmshippy avatar lmshippy commented on August 30, 2024

I am using a custom index file, and a custom template. The problem is not with that, the problem I am having is with being a pull the interfaces dynamically and then use them with with_items. Basically following the example Jason posted in the link below.

http://jedelman.com/home/network-automation-with-ansible-dynamically-configuring-interface-descriptions/

from ntc-ansible.

jedelman8 avatar jedelman8 commented on August 30, 2024

Hi @lmshippy,

Can you show the output running in verbose mode or add a task like this:

debug: var=interface

And do this after your set_fact task. Show us this output.

Thanks.

from ntc-ansible.

lmshippy avatar lmshippy commented on August 30, 2024

image

from ntc-ansible.

jedelman8 avatar jedelman8 commented on August 30, 2024

Actually something seems off. You did a debug and you're still seeing the response key. Let's eliminate the set_fact for now and just do this:

with_items: "{{ interfaces.response }}"

from ntc-ansible.

lmshippy avatar lmshippy commented on August 30, 2024

Here is the new playbook and below is the debug output.

---

  - name: COLLECT DATA TEST
    hosts: iosrouters
    gather_facts: no
    connection: local

    tasks:
      - name: GET INTERFACES
        ntc_show_command:
          connection=ssh
          platform={{ vendor }}_{{ os }}_{{ api }}
          index_file=index
          template_dir=/usr/lib/python2.7/dist-packages/ansible/modules/ntc-ansible/ntc-templates/templates
          command='show ip int brief'
          host={{ inventory_hostname }}
          username={{ un }}
          password={{ pwd }}
        tags: test
        register: interfaces

      - name: GET INTERFACES DETAIL
        ntc_show_command:
          connection=ssh
          platform={{ vendor }}_{{ os }}_{{ api }}
          index_file=interface.index
          template_dir=/usr/lib/python2.7/dist-packages/ansible/modules/ntc-ansible/ntc-templates/templates
          command="show run int {{ item.intf }}"
          host={{ inventory_hostname }}
          username={{ un }}
          password={{ pwd }}
        tags: test
        with_items: "{{ interfaces.response }}"
        register: interfaceinfo



TASK [GET INTERFACES] **********************************************************
ok: [x.x.x.x] => {"changed": false, "response": [{"intf": "Embedded-Service-Engine0/0", "ipaddr": "unassigned", "proto": "down", "status": "administratively down"}, {"intf": "GigabitEthernet0/0", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, {"intf": "GigabitEthernet0/1", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, {"intf": "Loopback0", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, {"intf": "Tunnel1", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, {"intf": "Tunnel2", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}], "response_list": []}

TASK [GET INTERFACES DETAIL] ***************************************************
ok: [x.x.x.x] => (item={u'status': u'administratively down', u'intf': u'Embedded-Service-Engine0/0', u'ipaddr': u'unassigned', u'proto': u'down'}) => {"changed": false, "item": {"intf": "Embedded-Service-Engine0/0", "ipaddr": "unassigned", "proto": "down", "status": "administratively down"}, "response": [{"helper": "", "hsrp": "", "interface": "Embedded-Service-Engine0/0", "ip_addr": "", "sub_mask": ""}], "response_list": []}
ok: [x.x.x.x] => (item={u'status': u'up', u'intf': u'GigabitEthernet0/0', u'ipaddr': u'x.x.x.x', u'proto': u'up'}) => {"changed": false, "item": {"intf": "GigabitEthernet0/0", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, "response": [{"helper": "", "hsrp": "", "interface": "GigabitEthernet0/0", "ip_addr": "x.x.x.x", "sub_mask": "x.x.x.x"}], "response_list": []}
ok: [x.x.x.x] => (item={u'status': u'up', u'intf': u'Loopback0', u'ipaddr': u'x.x.x.x', u'proto': u'up'}) => {"changed": false, "item": {"intf": "Loopback0", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, "response": [{"helper": "", "hsrp": "", "interface": "Loopback0", "ip_addr": "x.x.x.x", "sub_mask": "x.x.x.x"}], "response_list": []}
ok: [x.x.x.x] => (item={u'status': u'up', u'intf': u'Tunnel1', u'ipaddr': u'x.x.x.x', u'proto': u'up'}) => {"changed": false, "item": {"intf": "Tunnel1", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, "response": [{"helper": "", "hsrp": "", "interface": "Tunnel1", "ip_addr": "x.x.x.x", "sub_mask": "x.x.x.x"}], "response_list": []}
ok: [x.x.x.x] => (item={u'status': u'up', u'intf': u'Tunnel2', u'ipaddr': u'x.x.x.x', u'proto': u'up'}) => {"changed": false, "item": {"intf": "Tunnel2", "ipaddr": "x.x.x.x", "proto": "up", "status": "up"}, "response": [{"helper": "", "hsrp": "", "interface": "Tunnel2", "ip_addr": "x.x.x.x", "sub_mask": "x.x.x.x"}], "response_list": []}

from ntc-ansible.

jedelman8 avatar jedelman8 commented on August 30, 2024

Looks like it worked...what am I missing?

If you add a debug: var=interfaceinfo, you should have what you need, no?

from ntc-ansible.

lmshippy avatar lmshippy commented on August 30, 2024

Actually looking, you are correct, the information is in there. The file we were creating was putting in a bunch of extra stuff at the top but we were able to figure it out. Quick question, with the loop it is reconnecting to the device each time for the looped command, is there any way to have it maintain the connection for the loop?

from ntc-ansible.

GGabriele avatar GGabriele commented on August 30, 2024

Hey @lmshippy ,

this is not possible yet, but it's a feature we will release in the future :)

from ntc-ansible.

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.