Push config across the devices and skip if it is configured already

Hi i’m new to NORNIR. I’m looking the solution same as NAPALM where i can check the difference and if some commands are already in device, we can skip rather than configuring again. Is there way to apply same concept in NORNIR?

Below is my sample script to push NTP server.

from nornir import InitNornir
from nornir.plugins.tasks.networking import netmiko_send_command,netmiko_send_config
from nornir.plugins.functions.text import print_result,print_title

nr = InitNornir(
config_file=“config.yaml”, dry_run =True
)

def lb_create(lb_task):
lb_task.run(task=netmiko_send_config, config_file =“config_update NTP server”)

results = nr.run(task = lb_create)
print_title(“NETMIKO DEMO”)
print_result(results)

If you are using Netmiko directly, then you would have to create your own checks in a custom Nornir task.

In other words, netmiko_send_config will just blindly send the configuration commands you have specified. It has no awareness of whether the configuration elements already exist or not. Consequently, you would have to create a custom task that checked for the things you were configuring and then made decisions based on the show command output you retrieved. I.E. you would have to create this intelligence yourself.

Another option is to use Nornir + NAPALM especially NAPALM and full configuration replace (as NAPALM’s full configuration replace should generally know whether the new configuration already exists or not).

thank you @ktbyers. Actually i want to import napalm in nornir and want to take advantage of NAPALM to replace config like compare_config() and replace the missing config only not replacing whole config.

found this post which might be helpful for what i’m doing. will try today and let you know.

i went through documentation and tried same script. i got the output what i’m looking for. it’s really cool feature.

from nornir import InitNornir
from nornir.plugins.tasks import networking, text
from nornir.plugins.functions.text import print_title, print_result

nr = InitNornir(config_file=“config.yaml”, dry_run=False)
cmh = nr.filter(site=“cmh”, type=“network_device”)

def basic_configuration(task):
# Transform inventory data to configuration via a template file
r = task.run(task=text.template_file,
name=“Base Configuration”,
template=“base.j2”,
path="/root/test"
)

# Save the compiled configuration into a host variable
task.host["config"] = r.result

# Deploy that configuration to the device using NAPALM
task.run(task=networking.napalm_configure,
         name="Loading Configuration on the device",
         replace=False,
         configuration=task.host["config"])

print_title(“Playbook to configure the network”)
result = cmh.run(task=basic_configuration)
print_result(result)

**** Playbook to configure the network *****************************************
basic_configuration*************************************************************

  • spine00.cmh ** changed : True ************************************************
    vvvv basic_configuration ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
    ---- Base Configuration ** changed : False ------------------------------------- INFO
    ip access-list extended TTL
    permit gre any any
    permit igmp any any
    permit tcp any any
    permit ospf any any
    permit icmp any any
    ---- Loading Configuration on the device ** changed : True --------------------- INFO
    +ip access-list extended TTL
  • permit ospf any any
  • permit icmp any any
    ^^^^ END basic_configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • spine01.cmh ** changed : False ***********************************************
    vvvv basic_configuration ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
    ---- Base Configuration ** changed : False ------------------------------------- INFO
    ip access-list extended TTL
    permit gre any any
    permit igmp any any
    permit tcp any any
    permit ospf any any
    permit icmp any any
    ---- Loading Configuration on the device ** changed : False -------------------- INFO
    ^^^^ END basic_configuration ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^