Ansible playbook to get all active L3 vlan interfaces from juniper switch

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

Installing the Junos EZ Library

This post follows on from my last post about the Junos EZ Library, Jeremy Schulman’s work to make Junos devices easily manageable via Python, even for those of us who are not hard core programmers by trade.

In order to run the Junos EZ library I had to prepare my Ubuntu system with a few pre-requisites. Jeremy’s first post talks about what’s required on his CentOS Developer Workstation; this post does the same for Ubuntu server.

Pre-Requisites

# Install the NETCONF 'ncclient' library:
pip-2.7 install git+https://github.com/Juniper/ncclient.git

# Install the Junos "EZ" library:
pip-2.7 install git+https://github.com/jeremyschulman/py-junos-eznc.git

But hold on, because those commands need other things to be in place in order to succeed. At the very least, along with the above, you will need Python 2.7 and the “pip–2.7” tool. On my Ubuntu server, I had Python 2.7 installed, but the rest took a few more steps.

Read more

Ansible Play Example

Ansible is an IT automation tool. It can configure systems, deploy software, and orchestrate more advanced IT tasks such as continuous deployments or zero downtime rolling updates.

Ansible’s goals are foremost those of simplicity and maximum ease of use. It also has a strong focus on security and reliability, featuring a minimum of moving parts, usage of OpenSSH for transport (with an accelerated socket mode and pull modes as alternatives), and a language that is designed around auditability by humans – even those not familiar with the program.

Read more