top of page

Self-Service Python Nornir scripts with Kriten

11 minutes ago
3 min read

Nornir is a popular pure-Python automation framework, from June 2026 it is stewarded, funded and further developed by Opsmill (https://opsmill.com).


This blog post demonstrates how a Python Nornir script can be onboarded and executed via Kriten. An example script is used to pull Arista inventory from Infrahub SoT using the nornir-infrahub plugin and collect health information from switches using Nornir over eAPI. The script ‘aristahealth_nornir.py’ is located in a public repository: https://github.com/kriten-io/kriten-community-toolkit in the ‘arista-health’ directory. It takes four parameters from environment variables:


  • USERNAME (Arista user login name with sufficient permissions to run show commands)

  • PASSWORD (Arista user password)

  • INFRAHUB_URL (URL to Infrahub SoT)

  • INFRAHUB_TOKEN (Infrahub Token)


Script works from command line as it is. Only modification from typical script is in order for Kriten to pick up any json data from script output, script has to print json data into stdout between "^JSON" delimeters.


To onboard script into Kriten it needs to be stored in a code repository, and there should be a container image, with expected python version and required packages (as per requirements.txt).


Running this script via Kriten offers following benefits:

  • Executor of the script have no access to the code and no access to secrets and no access to end systems.

  • Executor must authenticate with Kriten and have RBAC permission to execute the script;

  • Script can be executed via Rest API call, by AI Agent via MCP and with version 1.2.0 of Kriten via gRPC.

  • Script can be scheduled with built-in Kriten scheduler.



  1. Onboarding script into Kriten in two steps (we will perform those via UI):


a. Create runner


Runner needs URL for repo when script lives, PAT if private, branch if other than "main" and container image (code and container repo expected to be reachable from k8s cluster). We will be using container image "kubecodeio/infrahub-nornir:0.2" publicly available in docker hub, it contains required packages.



b. Create task, which will be using above runner. We have to provide path to script in that repository to execute it.



Script doesn't require any parameters, thus we keep Schema empty.


That's it. We can now execute script via UI and observe the result:




Job completed successfully:



And we can see the job result (trancated output):



We've demonstrated onboarding and run of the script via UI. Kriten also captures json between ^JSON delimeters and returns via Rest API call json_data in the response.


  1. Executing script by AI Agent via built-in Kriten MCP.


AI Agent talks to Kriten MCP via streamable HTTP, current supported authentication is via API Token, associated with a Kriten User. For AI Agent to see availble tasks, it must have have RBAC permission to "execute" those tasks and those tasks must have Schema description for AI Agent to know what to do with it (as well as parameters if any). We will add short description to a aristahealth-nornir task.



Below is transcript from the AI Agent (Opencode):




  1. Executing script via Kriten gRPC


Note: This feature will be available in upcoming Kriten release 1.2.0.


We will demonstrate it with Postman. Kriten has option to expose available gRPC services via Reflection (which can be disabled in prod for any security concerns). gRPC client has to use API token to authenticate with Kriten and to have permission for executing a task.


To demonstrate gRPC streaming, we've prepended "sleep 30" before running python command in the task, as script is very fast as there are not many switches in the Lab. It will allow us to execute task and have enough time to use WatchJob call to observe response from Kriten.


Below is a short video to show the "dynamics". First we will list available tasks, then we will execute task using it's id, we will capture job id in the response. Then we will watch streamed gRPC events for that job.



We haven't covered RBAC in this blog, as that is the subject on its own, we will follow up on RBAC in upcoming blog posts. API token we used was create for Admin user, which had sufficient privileges. RBAC is covered in online documentation on https://kriten.io.


 
 
bottom of page