Tasks
- nornir_routeros.plugins.tasks.routeros_command(task, path, command, changed=False, **kwargs)
Runs a RouterOS command such as ping or fetch.
- Parameters:
path (
str) – Path to the resource.command (
str) – Name of the command.kwargs – Args for the command. A trailing ‘_’ can be added to kwargs that conflict with that of Nornir’s.
- Return type:
Result
Examples
Ping 127.0.0.1 5 times:
nr.run( task=routeros_command, path="/", command="ping", address="127.0.0.1", count=5 )
- nornir_routeros.plugins.tasks.routeros_config_item(task, path, where, properties=None, add_if_missing=False, template_property_values=True)
Configures an item. Property values can be templated using jinja2. Use
hostto accesstask.host.- Parameters:
path (
str) – The path to where the item should be. Example: /ip/firewall/filter to configure firewall filters.where (
Dict[str,str]) – Dictionary of properties and values to find the item.properties (
Optional[Dict[str,str]]) – Desired properties of the item. IfNone, then any items matchingwherewill be removed.add_if_missing (
bool) – If an item matching the criteria inwheredoesn’t exist then one will be created.template_property_values (
bool) – Use Jinja2 for property values.
- Returns:
A
Resultwithresultset to the item after any changes.- Return type:
Result
Examples
Ensure the router hostname is set to the inventory name:
nr.run( task=routeros_config_item, path="/system/identity", where={}, properties={ "name": "{{ host.name }}" } )
Ensure the
wwwservice is disabled:nr.run( task=routeros_config_item, path="/ip/service", where={ "name": "www" }, properties={ "disabled": "true" } )
Ensure a script is configured:
nr.run( task=routeros_config_item, path="/system/script", where={ "name": "test" }, properties={ "name": "test" "source": ':log info "hello"\r\n:log info "world"\r\n' }, # To preserve \r\n line endings: template_property_values=False )
- nornir_routeros.plugins.tasks.routeros_get(task, path, **kwargs)
Returns a RouterOS resource. For kwargs such as
namethat conflict with Nornir’s, append an underscore.- Parameters:
path (
str) – Path to the resource. Example: /ip/firewall/filter for firewall filters.kwargs – Filter results by the given kwargs. A trailing ‘_’ can be added to kwargs that conflict with that of Nornir’s.
- Returns:
A
Resultwith result set to the item(s) under the given path.- Return type:
Result
Examples
Get RouterBoard information:
nr.run( task=routeros_get, path="/system/routerboard" )
Get non-dynamic addresses:
nr.run( task=routeros_get, path="/ip/address", dynamic="false" )