I have an inventory built out with multiple devices for example:
router1
router2
switch1
switch2
Once my inventory is initialized i pull a list of configurations that I want to push to each device, these are static configs.
I can’t seem to figure out how to specify which config file to send to each of the devices.
I was able to filter based on the name and do the run(task) but while that works, it does them all serially instead of threaded at the same time.
If I don’t filter, then it just loops through each device pushing the configs for the other 3 devices as well:
Demo mockup:
In this instance, it works, but processes each device one after another
# function called after init of nr
def BuildTempTemplates():
for hostname in nr.inventory.hosts:
thisdevid = nr.inventory.hosts[hostname].data['deviceid']
print("Processing " + hostname)
# This creates a temp file named deviceidconfig.text with the configs I want to push (2config.txt)
MyTempTemplate = BuildTempConfig(str(thisdevid)
device = nr.filter(devinvid=thisdevid)
result = device.run(task=napalm_configure, dry_run=True,
name="Pushing Generated Configs", filename=MyTempTemplate, replace=False)
if I remove the device = nr.filter…
Then it will loop through all 4 devices pushing all 4 generated configs to each device which I do not want as each config is different depending on the device
So how can I specify a per device configuration and have it push to all devices with the amount of workers I selected (10)?