We will be using passwordless ssh access to the switch, so ssh-rsa key has to be configured on the target switch.
All we need to do here is to ssh to the switch, run the command: "show interfaces vlan terse | match inet" and get vlan interface IDs from the output.
If the switch has vlan interfaces configured, the output will look like this:
vlan.501upup inet 10.5.5.10/24
vlan.601upup inet 10.6.6.10/24
The following python regex will be used to get vlan interface numbers:
pulled_vlans = re.findall(r'vlan.(\d{3})', cli_output)
We need to write a simple custom Python ansible module that will be called from the playbook.
**TIP: To make a custom module available to Ansible, you can either specify the path to your custom module in an environment variable, ANSIBLE_LIBRARY; use the --module-path command-line option, or drop the modules in a ./library directory alongside your top-level playbooks.
Read more
Junos PyEZ is a Python "micro-framework" to remotely manage or automate Junos OS devices. The user is NOT required to be a software programmer, have sophisticated knowledge of Junos OS, or have a complex understanding of the Junos OS XML API.
This library was built for two types of users:
Non-Programmers - Python as a Power Shell
This means that non-programmers, for example, the Network Engineer, can use the native Python shell on their management server (laptop, tablet, phone, and so on) as their point-of-control for remotely managing Junos OS devices. The Python shell is an interactive environment that provides the necessary means to perform common automation tasks, such as conditional testing, for-loops, macros, and templates. These building blocks are similar enough to other "shell" environments, like Bash, to enable the non-programmer to use the Python shell as a power tool, instead of a programming language. From the Python shell, a user can manage Junos OS devices using native hash tables, arrays, and so on, instead of using device-specific Junos OS XML or resorting to "screen scraping" the actual Junos OS CLI.
Programmers - Open and Extensible
There is a growing interest and need to automate the network infrastructure into larger IT systems. To do so, traditional software programmers, DevOps, hackers, and so on, need an abstraction library of code to further those activities. Junos PyEZ is designed for extensibility so that the programmer can quickly and easily add new widgets to the library in support of their specific project requirements. There is no need to "wait on the vendor" to provide new functionality. Junos PyEZ is not specifically tied to any version of Junos OS or any Junos OS product family.
Read more