Skip to content

Instantly share code, notes, and snippets.

View jeffbrl's full-sized avatar

Jeff Loughridge jeffbrl

View GitHub Profile
@jeffbrl
jeffbrl / ansible_user.conf.j2
Created December 30, 2016 23:45
Ansible playbook to create ansible user on junos device with private key authentication
system {
login {
user ansible {
class super-user;
authentication {
ssh-rsa "{{ ansible_public_key }}";
}
}
}
}
@jeffbrl
jeffbrl / software_upgrade.yml
Last active January 9, 2017 15:04
junos_install_os ansible example playbook
# This task upgrades software
- name: Upgrade junos software
hosts: all
connection: local
gather_facts: no
roles:
- Juniper.junos
vars_prompt:
- name: USER
prompt: Device user
@jeffbrl
jeffbrl / junos_jsnapy_examples.yml
Last active March 17, 2017 15:49
junos_jsnapy examples
# Based on examples at https://github.com/Juniper/ansible-junos-stdlib/blob/deb0f9bf4fbe0c0db6026d674a81d5b671dcf756/library/junos_jsnapy
# I tested my example using ansible-junos-stdlib commit deb0f9bf4fbe0c0db6026d674a81d5b671dcf756.
# The current version (3/17/2017) in Galaxy is 1.4.0. The junos_jsnapy module in 1.4.0 will not work with this example.
# The "err" and "info" messages work fine using the jsnapy command line tool; however, I can get them to display in the playbook
# run.
- name: BGP peer test
hosts: all
connection: local
gather_facts: no
@jeffbrl
jeffbrl / interface_test.yml
Last active January 19, 2017 12:22
jsnapy command line - check if interface exists
interface_test:
- rpc: get-interface-information
- args:
interface-name: et-2/0/0
- iterate:
xpath: //physical-interface
tests:
- exists: name
info: "Test succeeded. et-2/0/0 exists"
err: "Test failed. et-2/0/0 does not exist"
@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;
@jeffbrl
jeffbrl / Dockerfile
Created January 31, 2017 02:18
Fat ansible container
From phusion/baseimage:0.9.18
MAINTAINER Jeff Loughridge <jloughridge@acm.org>
RUN apt-get update && apt-get -y install --no-install-recommends \
git \
nano \
openssh-server \
python-apt \
software-properties-common
@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
- 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 / 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
@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")