Skip to content

Instantly share code, notes, and snippets.

View danielmacuare's full-sized avatar

Daniel Macuare danielmacuare

View GitHub Profile
danielmacuare /
Last active October 11, 2023 10:55
Simple tutorial to use nornir for network automation solutions. The tutorial explain some basics to start with.

Nornir - Tutorial

1 - Initialise a Nornir Object.

  r = InitNornir(config_file='config.yaml')
  nr = InitNornir(config_file='config.yaml', core={'num_workers': 1})		# Useful for testing as it works in serial, doesn't paralellise connections.

2 - Filtering Objects - Can be cumulative.

danielmacuare /
Last active July 5, 2021 05:38
To Install ANY python version on Linux boxes

Python - Building from source (Updated Dec 2020)

The following commands will help you to install Python 3.9.1 on a Centos 7 or Ubuntu 18.04 machine.

1 - Select the Python version you'll install. - We'll select the latest version as of Dec 2020 (3.9.1)

2 - Installing Python.

On Centos 7

sudo yum install gcc openssl-devel bzip2-devel libffi-devel
danielmacuare /
Last active September 14, 2020 14:52
AWS Lambda Function to Post an alert to a Slack channel every time Cloudwatch triggers the SNS-Backed Lambda
import logging
from json import dumps
from os import environ
from urllib3 import PoolManager
def post_to_slack(event, context):
slack_channel = environ.get("SLACK_NET_CHANNEL")
danielmacuare /
Last active April 19, 2020 08:19
Bolierplate to render an output file from a YAML (Vars) + Jinja (Template)
#!/usr/bin/env python3
import yaml
from jinja2 import Environment, FileSystemLoader, PackageLoader, StrictUndefined
# Docs:
# Functions
def render_yaml_template(yaml_file, jinja_template, output="files/sshd_config"):
This takes a yam file with all yor vars, a Jinja template and renders an output file
danielmacuare / python_docstrings.MD
Last active March 8, 2020 11:19
Python Docstrings Formats
danielmacuare / python_logging.MD
Last active March 7, 2020 18:41
Python Logging Boilerplate

Method 1 - With basicCofig() (Logging to a file)

#!/usr/bin/env python3
import logging

def conf_logging(log_sev='WARNING'):
    log_format = "[%(name)s]-[%(levelname)s]-%(asctime)s-[%(funcName)s]-%(message)s"
danielmacuare /
Last active December 14, 2019 17:57
Bash script to resolve names or IPs
# Function that will expect a list of arguments from the cli and will resolve them using the host command.
# It will return the dns records or Ips on stdout
# Example bash
# bash

Napalm get_facts to Nornir

The purpose of this gist is to gather facts from a network device with Napalm and Nornir alike.
This will help us understand how to use tasks in Nornir.


  • We will be using Telnet to connect to our devices. By default, Napalm uses SSH to connect (See Napalm optional args) to the IOS devices. For this reason, we will need to pass optional_arguments when instantiating the Napalm driver object.
  • r2 can be replaced with the device ip. In my case, I was working with host files in my OS.

Napalm Script


The following commands have been tested on Ubuntu 16.04
uname -a
Linux ubuntu 4.4.0-145-generic #171-Ubuntu SMP Tue Mar 26 12:43:40 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux


0 - Install the tool sudo apt-get install isc-dhcp-server