从 Nornir 2.3.0 隐蔽到 Nornir 3.2.0
需要从 shell 输入获取用户名和密码
def adapt_host_data(host):
host.username = Gusername
host.password = Gpassword
if __name__ == "__main__":
Gusername = input('Username: ')
Gpassword = getpass('Password: ')
nr = InitNornir(
inventory={
"plugin": "nornir.plugins.inventory.simple.SimpleInventory",
"options": {
"host_file": "./inventory/hostise.yaml",
"group_file": "./inventory/groups.yaml"
},
"transform_function": adapt_host_data,
},)
这在 Nornir 2.3.0 下工作正常。但我无法在 Nornir 3.2.0 下使用它。 请帮助
这是我得到的错误
Traceback (most recent call last):
File "filesname.py", line 70, in <module>
"transform_function": adapt_host_data,
File "/heim/tahir/scripts/Python/nornir/envNornir3/lib64/python3.6/site-packages/nornir/init_nornir.py", line 72, in InitNornir
inventory=load_inventory(config),
File "/heim/tahir/scripts/Python/nornir/envNornir3/lib64/python3.6/site-packages/nornir/init_nornir.py", line 19, in load_inventory
inventory_plugin = InventoryPluginRegister.get_plugin(config.inventory.plugin)
File "/heim/tahir/scripts/Python/nornir/envNornir3/lib64/python3.6/site-packages/nornir/core/plugins/register.py", line 76, in get_plugin
raise PluginNotRegistered(f"plugin {name!r} is not registered")
nornir.core.exceptions.PluginNotRegistered: plugin 'nornir.plugins.inventory.simple.SimpleInventory' is not registered
Need to get username and password from shell input
def adapt_host_data(host):
host.username = Gusername
host.password = Gpassword
if __name__ == "__main__":
Gusername = input('Username: ')
Gpassword = getpass('Password: ')
nr = InitNornir(
inventory={
"plugin": "nornir.plugins.inventory.simple.SimpleInventory",
"options": {
"host_file": "./inventory/hostise.yaml",
"group_file": "./inventory/groups.yaml"
},
"transform_function": adapt_host_data,
},)
This is working fine under Nornir 2.3.0. But iam not able to use this under Nornir 3.2.0.
Please help
This is the error i get
Traceback (most recent call last):
File "filesname.py", line 70, in <module>
"transform_function": adapt_host_data,
File "/heim/tahir/scripts/Python/nornir/envNornir3/lib64/python3.6/site-packages/nornir/init_nornir.py", line 72, in InitNornir
inventory=load_inventory(config),
File "/heim/tahir/scripts/Python/nornir/envNornir3/lib64/python3.6/site-packages/nornir/init_nornir.py", line 19, in load_inventory
inventory_plugin = InventoryPluginRegister.get_plugin(config.inventory.plugin)
File "/heim/tahir/scripts/Python/nornir/envNornir3/lib64/python3.6/site-packages/nornir/core/plugins/register.py", line 76, in get_plugin
raise PluginNotRegistered(f"plugin {name!r} is not registered")
nornir.core.exceptions.PluginNotRegistered: plugin 'nornir.plugins.inventory.simple.SimpleInventory' is not registered
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要注册 InventoryPluginRegister 和 SimpleInventory
并且 config.yaml 必须如下所示
Needed to register InventoryPluginRegister and SimpleInventory
And the config.yaml have to look like this