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
ANKIT-OS/STYLISH-TEXT is a special repository. Its Is A Telegram Bot Which Can Translate Your Text Into 100+ Language

🔥 ᴳᴼᴼᴳᴸᴱ⁻ᵀᴿᴬᴺᔆᴸᴬᵀᴱᴿ 🔥 The owner would not be responsible for any kind of bans due to the bot. • ⚡ INSTALLING ⚡ • • 🛠️ Lᴀɴɢᴜᴀɢᴇs Aɴᴅ Tᴏᴏʟs 🔰 • If

ANKIT KUMAR 1 Dec 23, 2021
A python script fetches all your starred repositories from your GitHub account and clones them to your server so you will never lose important resources

A python script fetches all your starred repositories from your GitHub account and clones them to your server so you will never lose important resources

Ringo Hoffmann 27 Oct 01, 2022
A Telegram bot that scrapes websites for available vaccination appointments to notify users. (German)

@dachau_impf_bot 🇬🇧 A Telegram bot to check the contents of https://termin.dachau-med.de for available slots and inform users of the available dates

1 Nov 21, 2021
:snake: A simple library to fetch data from the iTunes Store API made for Python >= 3.5

itunespy itunespy is a simple library to fetch data from the iTunes Store API made for Python 3.5 and beyond. Important: Since version 1.6 itunespy no

Fran González 56 Dec 22, 2022
A PowerFull Telegram Mirror Bot.......

- [ DEAD REPO AND NO MORE UPDATE ] Slam Mirror Bot Slam Mirror Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Interne

αвιנтн 2 Nov 09, 2021
szrose is an all in one group management bot made for managing your group effectively with some advance security tools & Suit For All Your Needs ❤️

szrose is an all in one group management bot made for managing your group effectively with some advance security tools & Suit For All Your Needs ❤️

szsupunma 93 Jan 07, 2023
Scrapping malaysianpaygap & Extracting data from the Instagram posts

Scrapping malaysianpaygap & Extracting data from the posts Recently @malaysianpaygap has gotten quite famous as a platform that enables workers throug

Yudhiesh Ravindranath 65 Nov 09, 2022
Скрипт, позволяющий импортировать плейлисты из Spotify, а также обычные треклисты в VK музыку.

vk-music-import Программа для переноса плейлистов из Spotify и текстовых треклистов в VK Музыку. Преимущества: Позволяет быстро импортировать плейлист

Mew Forest 32 Nov 23, 2022
Telegram bot that search for the classrooms status of the chosen day and then return all the free classrooms using your preferred time slot

Aule Libere Polimi Since the PoliMi site no longer allows people to search for free classrooms this bot was necessary! It simply search for the classr

Daniele Ferrazzo 16 Nov 09, 2022
A light wrapper around FedEx's SOAP API.

Python FedEx SOAP API Module Author: Greg Taylor, Radek Wojcik Maintainer: Python FedEx Developers License: BSD Status: Stable What is it? A light wra

155 Dec 16, 2022
A Sublime Text plugin that displays inline images for single-line comments formatted like `// ![](example.png)`.

Inline Images Sometimes ASCII art is not enough. Sometimes an image says more than a thousand words. This Sublime Text plugin can display images inlin

Andreas Haferburg 8 Jul 01, 2022
Simple spam bot made in python

Simple Spam Bot A Simple and easy way to be the most hated person between your friends, All you have to do is spam the group chat using this bot until

Kareem Osama 6 Sep 05, 2022
𝗖𝝠𝝦𝝩𝝠𝝞𝝥 𝝦𝗥𝝞𝗖𝝽°™️ 🇱🇰 Is An All In One Media Inline Bot Made For Inline Your Media Effectively With Some Advance Security Tools♥️

𝗖𝝠𝝦𝝩𝝠𝝞𝝥 𝝦𝗥𝝞𝗖𝝽° ™️ 🇱🇰 𝗙𝗘𝝠𝝩𝗨𝗥𝗘𝗦 Auto Filter IMDB Admin Commands Broadcast Index IMDB Search Inline Search Random Pics Ids & User I

Kɪꜱᴀʀᴀ Pᴇꜱᴀɴᴊɪᴛʜ Pᴇʀᴇʀᴀ 〄 13 Jun 21, 2022
Accurately dump Commodore 64 tapes

TrueTape64 A cheap, easy to build adapter to interface a Commodore 1530 (C2N) Datasette to your PC to dump and preserve your aging Commodore 64 softwa

francesco 38 Dec 03, 2022
A code that can make your 5 accounts stay 24/7 in a discord voice channel!

Voicecord A code that can make your 5 accounts stay 24/7 in a discord voice channel! Usage ・Fork the repo ・Clone it to replit ・Install the required pa

DraKenCodeZ 3 Jan 09, 2022
Python API wrapper around Trello's API

A wrapper around the Trello API written in Python. Each Trello object is represented by a corresponding Python object. The attributes of these objects

Richard Kolkovich 904 Jan 02, 2023
A Telegram Bot with(Forwarder Bot + User Bot + More Features )

A Telegram Bot with(Forwarder Bot + User Bot + More Features )

Kaif 3 Feb 16, 2022
QR login for pyrogram client

Generate Pyrogram session via QRlogin

ポキ 18 Oct 21, 2022
Script for polybar to display and control media(not only Spotify) using DBus.

polybar-now-playing Script for polybar to display and control media(not only Spotify) using DBus Python script to display and control current playing

Dope Wizard 48 Dec 31, 2022
buys ethereum based on graphics card moving average price on ebay

ebay_trades buys ethereum based on graphics card moving average price on ebay Built as a meme, this application will scrape the first 3 pages of ebay

ConnorCreate 41 Jan 05, 2023