nornir-automation / nornir

Pluggable multi-threaded framework with inventory management to help operate collections of devices
https://nornir.readthedocs.io/
Apache License 2.0
1.38k stars 234 forks source link

Does support to initialize SimpleInventory with native objects still work? #825

Closed kyoungwookmin closed 1 year ago

kyoungwookmin commented 1 year ago

Does support to initialize SimpleInventory with native objects still work? nornir.version is 3.3.0

I'm trying various things, but I'm getting an error.

  1. TypeError: SimpleInventory.init() got an unexpected keyword argument 'hosts'
    from nornir import InitNornir
    nr = InitNornir(inventory={
    "plugin": "SimpleInventory",
    "options": {
        "hosts": {
            "host1": {
                "username": "user",
                "groups": ["group_a"],
                "data": {"a": 1, "b": 2},
            },
        },
        "groups": {"group_a": {"platform": "linux"}},
        "defaults": {"data": {"a_default": "asd"}},
    }
    })
  2. PluginNotRegistered: plugin 'nornir.plugins.inventory.SimpleInventory' is not registered
    
    from nornir import InitNornir
    from nornir.plugins.inventory import SimpleInventory
    from nornir.core.plugins.inventory import InventoryPluginRegister
    InventoryPluginRegister.register("SimpleInventory", SimpleInventory)

nr = InitNornir(inventory={

"plugin": "SimpleInventory",

"plugin": "nornir.plugins.inventory.SimpleInventory",
"options": {
    "hosts": {
        "host1": {
            "username": "user",
            "groups": ["group_a"],
            "data": {"a": 1, "b": 2},
        },
    },
    "groups": {"group_a": {"platform": "linux"}},
    "defaults": {"data": {"a_default": "asd"}},
}

})

dbarrosop commented 1 year ago

Not since 2+ years ago when nornir 3 was released. If you want to create your inventory programmatically you will either need to write your own inventory plugin or leverage some third party one. If I am not mistaken nornir_salt includes one you may be able to leverage.

dbarrosop commented 1 year ago

Closing as this is not a nornir issue.