Use CSV files as a Nornir Inventory source with hosts, groups and defaults.

Overview

nornir_csv

published

Use CSV files as a Nornir Inventory source with hosts, groups and defaults. This can be used as an equivalent to the Simple Inventory plugin but using CSV files instead of YAML. This does not generate any new files, but instead reads host data from three files:

  • hosts.csv
  • groups.csv
  • defaults.csv

Installation

As of right now, the code hasn't been published to PyPi, so it must be installed from source. Be sure to clone the repository locally:

cd /directory/where/you/clone/git/stuff/
git clone https://github.com/matman26/nornir_csv.git

The nornir_csv directory can then be copied to your project root and added as an external library.

cp nornir_csv/nornir_csv /destination/project/root

Usage

Since this is an external plugin for Nornir 3.0+, it must be registered before usage. The main project file must therefore contain something similar to:

from nornir import InitNornir
from nornir_csv.plugins.inventory.csv_inventory import CsvInventory
from nornir.core.plugins.inventory import InventoryPluginRegister

InventoryPluginRegister.register("CsvInventoryPlugin", CsvInventory)

nr = InitNornir(config_file='sample_config.yaml')

By default, the plugin will look for the files hosts.csv, groups.csv and defaults.csv inside the ./inventory/ directory, but the directory can be changed by specifying the plugin option inventory_dir_path. A sample file such as below can be used:

inventory:
  plugin: CsvInventoryPlugin
  options:
    inventory_dir_path: /path/to/inventory/dir/
runner:
  plugin: threaded
  options:
    num_workers: 20

The name of the csv files to be read for hosts, groups and defaults can also be customized by setting the options hosts_file, groups_file and defaults_file, respectively. These should correspond to the file's basenames (no paths) with extension, if any.

CSV Syntax

Hosts

The hosts_file follows a specific syntax to make it nornir-compatible, see sample below:

name,hostname,username,password,port,platform,groups,custom_var
R1,192.168.122.10,cisco,cisco,22,cisco_ios,core main,foo
R2,192.168.122.20,cisco,cisco,22,cisco_xr,,bar

Note that name, hostname, username, password, port, platform and groups are nornir base attributes. This means they are hosts attributes directly, such that

nr.inventory.hosts['R1'].password

will yield the return value of 'cisco' as expected. Any custom variables that are added will be put inside the 'data' dictionary on the target host. So

nr.inventory.hosts['R1'].data['custom_var']

will return 'foo'.

Notice also that to specify the list of groups to which a host belongs the list must be specified one group at a time, separated by spaces. In the csv above, R1 belongs to the groups 'core' and 'main'. A hosts file is mandatory.

Groups

The groups_file is optional. It can be used to set default values for the base attributes of each host (for example, if every host of the same group uses the same credentials). Any attributes that are non-base attributes will be added to the 'data' container inside the generated group, similar to how it behaves with hosts. If no groups are specified in the csv file, hosts can still be assigned to groups but these will hold no data.

name,username,password,dns_server
core,cisco,cisco,8.8.8.8
main,,,,

Notice that the groups csv does not have any mandatory fields other than name.

Defaults

The defaults_file specifies any default variables. This file is also free-form, but is only composed of two lines: a header with the name of the variable and a second line with its value. The defaults file is optional.

message_of_the_day,foo,port
hello world!,bar,22
You might also like...
Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features! πŸ₯°
Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features! πŸ₯°

CallMusicPlus69 This Repo base on! πŸ€—οΈ A CallsMusic Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features

This bot can mention members upto 10,000 in groups and can mention members upto 200 in channels !

Mention All Bot This bot can mention members upto 10,000 in groups and can mention members upto 200 in channels ! 🏷 Infomation Language: Python. Tele

❀️A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules
❀️A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules

Natsuki Based on Python Telegram Bot Contributors Video Tutorial: Complete guide on deploying @TheNatsukiBot's clone on Heroku. β˜† Video by Sadew Jayas

Telegram bot to stream videos in telegram voicechat for both groups and channels

Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live streams, YouTube videos and telegram media. With record stream support, Schedule streams, and many more.

Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.
Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Telegram bot to stream videos in telegram voicechat for both groups and channels.
Telegram bot to stream videos in telegram voicechat for both groups and channels.

Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live streams, YouTube videos and telegram media. With record stream support, Schedule streams, and many more.

Add members to unlimited telegram channels and groups
Add members to unlimited telegram channels and groups

Program Features πŸ“Œ Coded with Python version 10. πŸ“Œ without the need for a proxy. πŸ“Œ without the need for a Telegram ID. πŸ“Œ Ability to add infinite p

Telegram bot to stream videos in telegram Voice Chat for both groups and channels

Telegram bot to stream videos in telegram Voice Chat for both groups and channels. Supports live steams, YouTube videos and telegram media. Supports scheduling streams, recording and many more.

An interactive and multi-function Telegram bot, made especially for Telegram groups.

PyKorone An interaction and fun bot for Telegram groups, having some useful and other useless commands. Created as an experiment and learning bot but

Comments
  • Request: To have more complex csv with data and for nornir_scrapli usecases

    Request: To have more complex csv with data and for nornir_scrapli usecases

    I use more fields in yaml for example of host file below, how can this be documented in CSV? specially for headers like, data: connection_options:, scrapli:, and scrapli_netconf:


    rtr1: hostname: 10.91.11.11 data: interface: TenGigE0/0/0/16 localmepid: 1 remotemepid: 2 rd: 1600 evi: 2600 xrsw: 7.1.2 connection_options: scrapli: platform: cisco_iosxr port: 22 extras: ssh_config_file: True auth_strict_key: False scrapli_netconf: port: 830 extras: ssh_config_file: True auth_strict_key: False

    enhancement 
    opened by jbl241987 5
  • ModuleNotFoundError: No module named 'nornir_csv.plugins'

    ModuleNotFoundError: No module named 'nornir_csv.plugins'

    Hi, thanks for such plugin, I was looking for something like this for sometime. It is really simple, but when I try I get this error

    ModuleNotFoundError: No module named 'nornir_csv.plugins'

    I have the package installed though

    Package Version


    importlib-metadata 4.10.1 mypy-extensions 0.4.3 nornir 3.2.0 nornir-csv 0.1.3

    repo for reference https://github.com/jbl241987/Nornir_Project.git

    opened by jbl241987 5
  • [Bug] Default value handling for Hosts

    [Bug] Default value handling for Hosts

    thanks @matman26 , I will definitely try this option also.

    One more query, I have used hosts.csv as exactly shown in Readme. But i want to remove username and password from hosts.csv and keep only in defaults.csv or groups.csv

    I tried that but that doesn't work. Seems it is mandatory in hosts.csv.

    How can I make it work?

    Originally posted by @jbl241987 in https://github.com/matman26/nornir_csv/issues/2#issuecomment-1019105423

    bug 
    opened by matman26 2
Releases(v0.3)
Owner
Matheus Augusto da Silva
Compulsive-obsessive Bash scripter | Network Programmability and Automation
Matheus Augusto da Silva
A Discord bot made by QwertyIsCoding

QwertyBot QwertyBot A Discord bot made by QwertyIsCoding Explore the docs Β» View Demo . Report Bug . Request Feature About The Project This Discord bo

4 Oct 08, 2022
Twitter feed of newly published articles in Limnology

limnopapers Code to monitor limnology RSS feeds and tweet new articles. Scope The keywords and journal choices herein aim to focus on limnology (the s

7 Dec 20, 2022
Detects members having unicode names. Public bot: @scarletwitchprobot

✨ Scarletwitch bot ✨ Detects unicode names members in a tg chat & provides a option to take action on that user ! Public bot: @scarletwitchprobot Supp

ÁÑÑÍHÌLΓ…TØR SPΓ„RK 18 Nov 12, 2022
♻️ API to run evaluations of the FAIR principles (Findable, Accessible, Interoperable, Reusable) on online resources

♻️ FAIR enough 🎯 An OpenAPI where anyone can run evaluations to assess how compliant to the FAIR principles is a resource, given the resource identif

Maastricht University IDS 4 Oct 20, 2022
MCNameBot is a fast discord bot that is used to check the availability of a Minecraft name with a simple command.

MCNameBot MCNameBot is a fast discord bot that is used to check the availability of a Minecraft name with a simple command. If you would like to just

Killin 2 Oct 11, 2022
Bot made with Microsoft Azure' cloud service

IttenWearBot Autori: Antonio Zizzari Simone Giglio IttenWearBot Γ¨ un bot intelligente dotato di sofisticate tecniche di machile learning che aiuta gli

Antonio Zizzari 1 Jan 24, 2022
A Simple Telegram Inline Torrent Search Bot by @infotechIT

Torrent-Search-RoBot A Simple Telegram Inline Torrent Search Bot by @infotechIT. Torrent API Using api.infotech.wtf API Host Bot Deploy to Heroku Clic

InfoTech 0 May 05, 2022
A discord.py bot template with Cogs implemented.

discord-cogs-template A discord.py bot template with Cogs implemented. Instructions Before you start ⚠ Basic knowledge of python is required. Steps If

censor 2 Sep 02, 2022
Telegram Google Translater Bot

Google-Translater-Bot Hey Mo Tech, I am simple Google Translater Bot. I can translate any language to you selected language Team Mo Tech Deploy To Her

21 Dec 01, 2022
A Simple Voice Music Player

πŸ“€ π•π‚π”π¬πžπ«ππ¨π­ βˆšπ™π™šπ™–π™’βœ˜π™Šπ™˜π™©π™–π™«π™š NOTE JUST AN ENGLISH VERSION OF OUR PRIVATE SOURCE WAIT FOR LATEST UPDATES JOIN @π’π”πππŽπ‘π“ JOIN @𝐂?

TeamOctave 8 May 08, 2022
Valorant store offer discord-bot

Valorant store checker - Discord Bot Discord bot that shows your daily store offer without open the VALORANT by using the Ingame API. written using Py

STACIA 226 Jan 02, 2023
A discord token nuker With loads of options that will screw an account up real bad

A discord token nuker With loads of options that will screw an account up real bad, also has inbuilt massreport, GroupChat Spammer and Token/Password/Creditcard grabber and so much more!

XPTGR 0 Aug 07, 2022
Discord Bot written in Python that plays music in your voice channel

Discord Bot that plays music! I decided to create a simple Discord bot using Python in order to advance my coding skills. Please don't ask me for help

Eric Yeung 39 Jan 01, 2023
IMDb + Auto + Unlimited Filter BoT

Telegram Movie Bot Features Auto Filter Manuel Filter IMDB Admin Commands Broadcast Index IMDB search Inline Search Random pics ids and User info Stat

Team AlinaX 1 Dec 03, 2021
GitGram Bot. Bot Then Message You Your Repo Starts, Forks, And Many More

Yet Another GitAlertBot Inspired From Dev-v2's GitGram Run Bot: Local Host Git Clone Repo : For Telethon Version : git clone https://github.com/TeamAl

Alina RoBot 2 Nov 24, 2021
A smart tool to backup members πŸ“ˆ So you even after a raid/ ban you can easily restore them in seconds 🎲

πŸ€‘ Discord-backer πŸ€‘ A open-source Discord member backup and restore tool for your server. This can help you get all your members in 5 Seconds back af

John 29 Dec 21, 2022
πŸ”ͺ Block replies to viral tweets from users getting paid to promote useless products

This Tweet Took Off Ublock Origin filter list targeting long reply chains posted by twitter users who get paid to promote random products on viral twe

Xetera 12 Jan 14, 2022
Wallpaper API from wallpaperscraft.com

wallpaper-api Wallpaper API from https://wallpaperscraft.com for API documentation see https://maajid-wallpaper-api.deta.dev/docs How to Run first, cl

Athallah Muhammad Maajid 2 Apr 06, 2022
A Rich renderable for viewing Multiple Sequence Alignments in the terminal.

rich-msa A simple module to render colorful Multiple Sequence Alignment with rich in the terminal. πŸ”§ Installing Install the rich-msa package directly

Martin Larralde 64 Dec 04, 2022
A Bot To Find Telegram User ID Easily

Telegram ID Bot πŸ€– A Bot To Find Telegram User ID Easily Made with Python3 (C) @BXBotz Copyright permission under MIT License License - https://githu

MuFaz-TG 6 Nov 21, 2022