-1

I have a question about automating network nodes using Ansible.

I want to get configuration of network node involving vlans (actually I just want to see the last vlan used in node, so that I could automatically create the next one).

When I log in to the Junos router, I write this command:

show configuration | display set | match interfaces | match ae0 | match description

and I get like 17 lines of configurations, all involving vlans (last line is the last vlan created)

I thought I would use junos_command module for same command, register the output then show it in msg (first part of a bigger plan).

But it turns out that junos_command only lets me use show configuration which displays like 2500 lines of config.

Is there a way to make junos_command give me the desired output, or should I just work with the output given, try to parse it in some ways? Any suggestions?

The only downside I see is that getting and parsing that output would take time as it would be quite large and being able to minimise the output would increase efficiency.

And maybe some suggestions about parsing the output as well? Any other means besides regex filters?

1 Answers1

0

SO the answer to my question was to use cli_command module instead of junos_command.

One thing to have in mind is that the connection has to be setup as network_cli (ansible_connetion: network_cli and ansible_network_os: junos <- you can put those in task vars)

  tasks:
    - name: Gather router facts about the vlans
      vars:
        ansible_connection: network_cli
        ansible_network_os: junos
        router_interface_name: ae1
      cli_command:
        command: "show configuration | display set | match {{router_interface_name}} | match vlan"
      register: output