Skip to content

Instantly share code, notes, and snippets.

View jeffbrl's full-sized avatar

Jeff Loughridge jeffbrl

View GitHub Profile
@jeffbrl
jeffbrl / get-candidate-config.yml
Created March 16, 2017 18:00
Obtaining the candidate configuration from router
# This ansible playbook gets the candidation configuration
- name: Get configuration
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
tasks:
- name: Getting router configs
@jeffbrl
jeffbrl / pyez_config_filtering.py
Created March 10, 2017 12:31
PyEZ config filtering example
# Pulled from Google Groups post by Stacy Smith
# https://groups.google.com/forum/#!topic/junos-python-ez/1OfnulLkyn4
import sys
import getpass
from lxml import etree
from jnpr.junos.device import Device
# Python3 is input(), Python2 is raw_input()
@jeffbrl
jeffbrl / simple_test_v2.robot
Last active October 26, 2021 15:40
Simple test of a calculator function with the robot framework - v2
*** Settings ***
Documentation Check arithmetic operations
Resource ${EXEC_DIR}/resources/keywords.txt
# currently only prints to output.xml
Suite Setup math.setup
Suite Teardown math.teardown
*** Variables ***
@jeffbrl
jeffbrl / simple_test.robot_v1
Last active February 22, 2017 16:55
Simple test of a calculator function with the robot framework - v1
*** Settings ***
Documentation Check arithmetic operations
Library ${EXECDIR}/lib/easy_math.py WITH NAME math
# The setup and teardown functions currently only print messages to output.xml
Suite Setup math.setup
Suite Teardown math.teardown
@jeffbrl
jeffbrl / logger_example.py
Created February 15, 2017 17:02
My preferred python logging module configuration and usage
import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG,
format='%(asctime)s.%(msecs)d %(levelname)s %(module)s - %(funcName)s: %(message)s',
datefmt="%Y-%m-%d %H:%M:%S")
logging.debug("Here is a debug-level message")
@jeffbrl
jeffbrl / Dockerfile
Created February 10, 2017 19:13
Dockerfile for ssh container
# based on Duke Dougal's post at http://superuser.com/questions/844101/docker-login-via-ssh-always-asks-for-password
FROM ubuntu:trusty
ENV USER ubuntu
RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN adduser --disabled-password --gecos "" $USER
RUN adduser $USER sudo
ADD authorized_keys /home/$USER/.ssh/authorized_keys
RUN chown $USER /home/$USER/.ssh/authorized_keys
RUN chown -R $USER:$USER /home/$USER/.ssh/authorized_keys
- name: Get primary lo0 address
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
- cmprescott.xml
vars:
temp_dir: /tmp
USER: jeffl
@jeffbrl
jeffbrl / primary_lo0_xpath_expr
Created February 1, 2017 14:17
xpath expression to find the primary address of lo0 in Junos router configuration
//interfaces/interface[name='lo0']/unit[name='0']/family/inet/address/primary/preceding-sibling::name
@jeffbrl
jeffbrl / Dockerfile
Created January 31, 2017 02:18
Fat ansible container
From phusion/baseimage:0.9.18
MAINTAINER Jeff Loughridge <[email protected]>
RUN apt-get update && apt-get -y install --no-install-recommends \
git \
nano \
openssh-server \
python-apt \
software-properties-common
@jeffbrl
jeffbrl / jinja2_looping.j2
Last active January 25, 2017 03:20
Looping examples in jinja2
#jinja2: lstrip_blocks: True
{% set vlans_per_ifl = 10 %}
{% for ifd, int in host.uplinks.items() %}
{{ ifd }} {
description "{{ int.description }}";
apply-groups-except interface-properties;
vlan-tagging;
mtu 9432;