ืืื ืืืืจ!
ืืขืฆืื ืก ืืื ืืจืืืก ื ืืจืืืงื ืื
ืืึธืก ืืื ื ืืฉื ืืขืจ ืขืจืฉืืขืจ ืืืืง ืคึฟืึทืจ ืึทืืึท ืึท ืึทืจืืขื. ืืขืจ ืขืจืฉืืขืจ ืึธืคึผืฆืืข ืืื ืืืคึผืืึทืืขื ืึทื ืขืืืขืืข ืืึธืจ ืฆืืจืืง ืฆืืจืืง ืืื ืึทื ืกืึทืืืข ืืืขืจืกืืข 1.ืงืก.ืงืก. ืื ืืืขืืึธืกืืคึผืขื ืืื ืจืึทืจืขืื ืืขื ืืฆื ืืื ืืขืจืืืขืจ ืงืขืกืืืืขืจ ืจืึทืกืืื. ืืื ืืขื ืืื ืขื ืึทื ืื ืึทืจืืขื ืืื ืืื ื ืืฉื ืืืืคืฉืืืื ืืื ืึธืคื ืืื ืืืขืจืกืืขืก ืืขื ืขื ืืขืจืืืึทื ืืืงื ืึทื ืกืึทืืืข. ืืื ืืขืืขืก ืืึธื ืืืขื ืืขื ืืึทืจืฃ ืคืึธืจ, ืคึฟืึทืื ืื ืงืืื ืึธืืขืจ ืืึธืก ืจืึธื. ืึธืืขืจ, ืืขืจ ืขืจืฉืืขืจ ืืืื, ืืืฉืขื ืขืจืืืืื ื ืงืึธื ืคืืืก, ืฉืืขื ืืืง ืึทืจืืขื ืืืืขืจ ืงืืืจ, ืืืืง jinja2 ืืขืจ ืืึธืืึธืจ ืืื ืืึทื ื ืืขืืจืื ืืขื. ืืืขืจ ืืขืจ ืฆืืืืืืขืจ ืืืื - ืจืึธืืืื ื ืืืืก ืงืึธื ืคืืืก - ืืืืฉืึทืืืึทืื ืืขืืจืืื ืกืึทืคึผืจืืืืื. ืืื ืืื ื ืืื ืืึธืื ืฆื ืจืึธืืืื ื ืื ืงืึทื ืคืืืืขืจืืืฉืึทื ืจืืืึธืืืื ืฆื ืืขืืคื ืึท ืืื ืืขืจื ืืขืืืืกืขืก, ืขืืืขืืข ืคืื โโืืืึธืก ืืขื ืขื ืืืื ืืืืื ืืขืจ ืคืื ืงืืืึธืืขืืขืจืก ืึทืืืขืง, ื ืืฆื ืืขื ืืขืฆืืึทื ืืื ืืขืืืขื ืึท ืืืกื ื ืืื ืข.
ืืึธ ืืื ืืืื ืึทืจืืึทื ืืึธืื ืึทื ืืืื ืึทื ืกืขืจืืึทื ืื ืืืื ืจืืึฟ ืืกืชึผืื ืืื ืืืื ืืึทื ืื ืคืื ืคืึทืืืืืขืจืึทืื ืืื ืึทื ืกืึทืืืขืืื ืืื ืืืจืข ืืกืจืื ืืช. ืืื ืืึธืก, ืืื, ืืื ืึท ืืืืืืืง ืคืื ื. ืึทื ืกืึทืืืข ืืื ืึท ืืึธืจ ืืึทืืื ืืขืจ, ืืืื ืืืืืขื ืข ืฉืื ืคืื ืืืืกื ืืื ืืืื ืืืืืขื ืข DSL (Domain Specific Language), ืืืึธืก ืืืื ืืืื ืืืื ืืืื ื ืืืืฃ ืึท ืืืืขืจ ืืืจืื. ื ื, ืึทื ืืึธืืขื ื ืึทื ืึทื ืกืึทืืืข ืขืก ืืื ืืขืืืขืืึธืคึผืื ื ืืึทื ืฅ ืืขืฉืืืื ื, ืืื ืึธื ืกืคึผืขืฆืืขื ืืืืื ื ืคึฟืึทืจ ืฆืืจืืง ืงืึทืืคึผืึทืืึทืืืืึทืื, ืขืก ืืื ื ืืฉื ืืืืื ืืืืื.
ืืขืจืืืขืจ, ื ืื ืึทืืื ืืึทื ื ืฆืืจืืง ืึท ืฆืืืืื ืืืขืจืกืืข ืคืื โโืื ืืืขืืึธืกืืคึผืขื ืืื ืืืคึผืืึทืืขื ืึทื. ืืึธืก ืืึธื ืืืืฃ ืคึผืืืืึธื, ืึธืืขืจ ืืึทื ืฅ ืืืืฃ ืึท ืคืจืืืืืืขืจืง ืืขืฉืจืืื ืืื ืคึผืืืืึธื ืืื ืคึฟืึทืจ ืคึผืืืืึธื ืืขืจืืคื
ืืืื โ ื ืึธืจื ืืจ ืืื ืึท ืืืงืจืึธืคืจืึทืืขืืืึธืจืง ืืขืฉืจืืื ืืื ืคึผืืืืึธื ืืื ืคึฟืึทืจ ืคึผืืืืึธื ืืื ืืืืืื ื ืคึฟืึทืจ ืึธืืึทืืืืฉืึทื. ืื ืืขืืืข ืืื ืืื ืืขื ืคืึทื ืืื ืึทื ืกืึทืืืข, ืฆื ืกืึธืืืืข ืคึผืจืึธืืืขืืก ืืึธ, ืงืึธืืคึผืขืืขื ื ืืึทืื ืฆืืืจืืืืื ื ืืื ืคืืจืืื ืื, ื.ืข. ืื ืืืึทื ืืึธืจื ืคืื ืืื ืืช ืืื ืืืืขืจ ืคึผืึทืจืึทืืขืืขืจืก, ืึธืืขืจ ืกืงืจืืคึผืก ืืขื ืขื ืืขืฉืจืืื ื ืืฉื ืืื ืึท ืืึทืืื ืืขืจ ืืกื, ืึธืืขืจ ืืื ืืขืจ ืืขืืืืงืขืจ ื ืืฉื ืืืืขืจ ืึทืื, ืึธืืขืจ ืืืืขืจ ืืื ืคึผ[ื|ื]ืืึธื.
ืืื ืก ืงืืง ืืื ืืืึธืก ืขืก ืืื ื ืืฆื ืื ืคืืืืขื ืืข ืืขืื ืืืึทืฉืคึผืื.
ืืื ืืึธืื ืึท ืฆืืืืึทื ื ืขืฅ ืืื ืขืืืขืืข ืืืฅ ืึธืคืึทืกืื ืืืืขืจ ืื ืืืื ื. ืืขืืขืจ ืึธืคืืก ืืื ืึท ืืืึทื ืจืึทืืืขืจ ืืืึธืก ืืขืจืืึทื ืืืฅ ืขืืืขืืข ืงืึธืืื ืืงืึทืฆืืข ืืฉืึทื ืึทืื ืคืื ืคืึทืจืฉืืืขื ืข ืึธืคึผืขืจืืืืขืจื. ืื ืจืืืื ื ืคึผืจืึธืืึธืงืึธื ืืื BGP. ืืืึทื ืจืึธืืืขืจืก ืงืืืขื ืืื ืฆืืืื ืืืืคึผืก: Cisco ISG ืึธืืขืจ Juniper SRX.
ืืืฆื ืื ืึทืจืืขื: ืืืจ ืืึทืจืคึฟื ืฆื ืงืึทื ืคืืืืขืจ ืึท ืืขืืึทืงืืืืึทื ืกืืื ืขื ืคึฟืึทืจ ืืืืืขื ืกืขืจืืืืืืึทื ืก ืืืืฃ ืึท ืืึทืืื ืืขืจ ืคึผืึธืจื ืืืืฃ ืึทืืข WAN ืจืึธืืืขืจืก ืคืื ืื ืฆืืืืึทื ื ืขืฅ - ืืขืืื ืืขื ืกืืื ืขื ืืื BGP - ืงืึทื ืคืืืืขืจ ืื ืืืืงืืึทื ืฉืืขืืจ ืคืื ืื ืืขืืึทืงืืืืึทื ืคึผืึธืจื.
ืขืจืฉืืขืจ, ืืืจ ืืึทืจืคึฟื ืฆื ืฆืืืจืืืื ืึท ืคึผืึธืจ ืคืื ืืขืืคึผืืึทืืขืก, ืืืืฃ ืืขืจ ืืืืข ืคืื โโืืืึธืก ืงืึทื ืคืืืืขืจืืืฉืึทื ื ืืืขื ืืืื ืืืฉืขื ืขืจืืืืึทื ืกืขืคึผืขืจืึทืืื ืคึฟืึทืจ ืกืืกืงืึธ ืืื ืืืฉืื ืืคึผืขืจ. ืขืก ืืื ืืืื ื ืืืืืง ืฆื ืฆืืืจืืืื ืืึทืื ืคึฟืึทืจ ืืขืืขืจ ืคืื ื ืืื ืงืฉืจ ืคึผืึทืจืึทืืขืืขืจืก, ื.ืข. ืงืืืึทืื ืื ืืขืืืข ืื ืืืึทื ืืึธืจื
ืืจืืื ืืืกืืขืจ ืคึฟืึทืจ Cisco:
$ cat templates/ios/base.j2
class-map match-all VIDEO_SURV
match access-group 111
policy-map VIDEO_SURV
class VIDEO_SURV
police 1500000 conform-action transmit exceed-action drop
interface {{ host.task_data.ifname }}
description VIDEOSURV
ip address 10.10.{{ host.task_data.ipsuffix }}.254 255.255.255.0
service-policy input VIDEO_SURV
router bgp {{ host.task_data.asn }}
network 10.40.{{ host.task_data.ipsuffix }}.0 mask 255.255.255.0
access-list 11 permit 10.10.{{ host.task_data.ipsuffix }}.0 0.0.0.255
access-list 111 permit ip 10.10.{{ host.task_data.ipsuffix }}.0 0.0.0.255 any
ืืืกืืขืจ ืคึฟืึทืจ ืืืฉืื ืืคึผืขืจ:
$ cat templates/junos/base.j2
set interfaces {{ host.task_data.ifname }} unit 0 description "Video surveillance"
set interfaces {{ host.task_data.ifname }} unit 0 family inet filter input limit-in
set interfaces {{ host.task_data.ifname }} unit 0 family inet address 10.10.{{ host.task_data.ipsuffix }}.254/24
set policy-options policy-statement export2bgp term 1 from route-filter 10.10.{{ host.task_data.ipsuffix }}.0/24 exact
set security zones security-zone WAN interfaces {{ host.task_data.ifname }}
set firewall policer policer-1m if-exceeding bandwidth-limit 1m
set firewall policer policer-1m if-exceeding burst-size-limit 187k
set firewall policer policer-1m then discard
set firewall policer policer-1.5m if-exceeding bandwidth-limit 1500000
set firewall policer policer-1.5m if-exceeding burst-size-limit 280k
set firewall policer policer-1.5m then discard
set firewall filter limit-in term 1 then policer policer-1.5m
set firewall filter limit-in term 1 then count limiter
ืืขืืคึผืืึทืืขืก, ืคืื ืงืืจืก, ืืึธื ื ืื ืงืืืขื ืืืืก ืคืื ืืื ืืืคื. ืืึธืก ืืขื ืขื ืืืืกืืงืื ืืืคืขืจืึทื ืกืื ืฆืืืืฉื ืื ืืจืืขืื ืงืึทื ืคืืืืขืจืืืฉืึทื ื ืืืึธืก ืืขื ืขื ืืขืืืขื ืืื ืืขื ืขื ืืขืืืขื ื ืึธื ืกืึทืืืืื ื ืื ืึทืจืืขื ืืืืฃ ืฆืืืื ืกืคึผืขืฆืืคืืฉ ืจืึธืืืขืจืก ืคืื ืคืึทืจืฉืืืขื ืข ืืึธืืขืืก.
ืคึฟืื ืืื ืืืขืจ ืืขืืคึผืืึทืืขืก ืืืจ ืืขื ืึทื ืฆื ืกืึธืืืืข ืื ืคึผืจืึธืืืขื, ืืืจ ื ืึธืจ ืืึทืจืคึฟื ืฆืืืื ืคึผืึทืจืึทืืขืืขืจืก ืคึฟืึทืจ ืืืฉืื ืืคึผืขืจ ืืื 3 ืคึผืึทืจืึทืืขืืขืจืก ืคึฟืึทืจ ืกืืกืงืึธ. ืืึธ ืืื ืืขื ืขื:
- ifname
- ipsuffix
- asn
ืืืฆื ืืืจ ืืึทืจืคึฟื ืฆื ืฉืืขืื ืื ืคึผืึทืจืึทืืขืืขืจืก ืคึฟืึทืจ ืืขืืขืจ ืืืื, ื.ืข. ืืึธื ืื ืืขืืืข ืืึทื ืื ืืืึทื ืืึธืจื.
ืคืึทืจ ืื ืืืึทื ืืึธืจื ืืืจ ืืืขืื ืฉืืจืขื ื ื ืึธืืคืึธืืื ืื ืืึทืงืืืืขื ืืืืฉืึทื
ืืึธืก ืืื, ืืึธืื ืืื ืื ืืึทืื ืื ืืขืืืข ืืขืงืข ืกืงืขืืขื:
.
โโโ config.yaml
โโโ inventory
โ โโโ defaults.yaml
โ โโโ groups.yaml
โ โโโ hosts.yaml
ืื config.yaml ืืขืงืข ืืื ืืขืจ ื ืึธืจืืึทื nornir ืงืึทื ืคืืืืขืจืืืฉืึทื ืืขืงืข
$ cat config.yaml
---
core:
num_workers: 10
inventory:
plugin: nornir.plugins.inventory.simple.SimpleInventory
options:
host_file: "inventory/hosts.yaml"
group_file: "inventory/groups.yaml"
defaults_file: "inventory/defaults.yaml"
ืืืจ ืืืขืื ืึธื ืืืืึทืื ืื ืืืืคึผื ืคึผืึทืจืึทืืขืืขืจืก ืืื ืืขืจ ืืขืงืข hosts.yaml, ืืจืืคึผืข (ืืื ืืืื ืคืึทื, ืืึธืก ืืขื ืขื ืืึธืืื ืก / ืคึผืึทืกืืืขืจืื) ืืื ืืจืืคึผืขืก.ืืึทืืืืื ืืื defaults.yaml ืืืจ ืืืขืื ื ืืฉื ืึธื ืืืืึทืื ืขืคึผืขืก, ืึธืืขืจ ืืืจ ืืึทืจืคึฟื ืฆื ืึทืจืืึทื ืืจืื ืืื ืืกืขืก ืืึธืจื - ืืืึธืก ืื ืืืงืืืฅ ืึทื ืืึธืก ืืื yaml ืื ืืขืงืข ืืื ืืืืืืง ืืึธืืฉ.
ืืึธืก ืืื ืืื hosts.yaml ืงืืงื ืืื:
---
srx-test:
hostname: srx-test
groups:
- juniper
data:
task_data:
ifname: fe-0/0/2
ipsuffix: 111
cisco-test:
hostname: cisco-test
groups:
- cisco
data:
task_data:
ifname: GigabitEthernet0/1/1
ipsuffix: 222
asn: 65111
ืืื ืืึธ ืืื ืืจืืคึผืขืก.ืืึทืื:
---
cisco:
platform: ios
username: admin1
password: cisco1
juniper:
platform: junos
username: admin2
password: juniper2
ืืืก ืืื ืืืึธืก ืืขืืจืืคื ืื ืืืึทื ืืึธืจื ืคึฟืึทืจ ืืื ืืืขืจ ืึทืจืืขื. ืืขืฉืึทืก ืื ืืืืึทืืืืึทืืืึธื, ืคึผืึทืจืึทืืขืืขืจืก ืคืื ืื ืืืึทื ืืึธืจื ืืขืงืขืก ืืขื ืขื ืืึทืคึผื ืฆื ืื ืืืืคืขืฅ ืืึธืืขื ืื ืืืขื ืืึธืจื ืขืืขืืขื ื.
ืื ืืขืจ ืืขืจ ืกืคึผืืืืขืจ ืืื ืึท ืืืึทืืจืึทืืข ืคืื โโืื InventoryElement ืืึธืืขื
print(json.dumps(InventoryElement.schema(), indent=4))
{
"title": "InventoryElement",
"type": "object",
"properties": {
"hostname": {
"title": "Hostname",
"type": "string"
},
"port": {
"title": "Port",
"type": "integer"
},
"username": {
"title": "Username",
"type": "string"
},
"password": {
"title": "Password",
"type": "string"
},
"platform": {
"title": "Platform",
"type": "string"
},
"groups": {
"title": "Groups",
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"data": {
"title": "Data",
"default": {},
"type": "object"
},
"connection_options": {
"title": "Connection_Options",
"default": {},
"type": "object",
"additionalProperties": {
"$ref": "#/definitions/ConnectionOptions"
}
}
},
"definitions": {
"ConnectionOptions": {
"title": "ConnectionOptions",
"type": "object",
"properties": {
"hostname": {
"title": "Hostname",
"type": "string"
},
"port": {
"title": "Port",
"type": "integer"
},
"username": {
"title": "Username",
"type": "string"
},
"password": {
"title": "Password",
"type": "string"
},
"platform": {
"title": "Platform",
"type": "string"
},
"extras": {
"title": "Extras",
"type": "object"
}
}
}
}
}
ืืขืจ ืืึธืืขื ืงืขื ืงืืงื ืึท ืืืกื ืงืึทื ืคืืืืื ื, ืกืคึผืขืฆืืขื ืืื ืขืจืฉืืขืจ. ืืื ืกืืจ ืฆื ืจืขืืขื ืขื ืขืก ืืืืก, ืื ืื ืืขืจืึทืงืืืื ืืึธืืข ืืื ืคึผืืืืึธื.
$ ipython3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from nornir import InitNornir
In [2]: nr = InitNornir(config_file="config.yaml", dry_run=True)
In [3]: nr.inventory.hosts
Out[3]:
{'srx-test': Host: srx-test, 'cisco-test': Host: cisco-test}
In [4]: nr.inventory.hosts['srx-test'].data
Out[4]: {'task_data': {'ifname': 'fe-0/0/2', 'ipsuffix': 111}}
In [5]: nr.inventory.hosts['srx-test']['task_data']
Out[5]: {'ifname': 'fe-0/0/2', 'ipsuffix': 111}
In [6]: nr.inventory.hosts['srx-test'].platform
Out[6]: 'junos'
ืืื ืืขืกืึธืฃ, ืืึธืื ืืื ืื ืืืื ืฆื ืื ืฉืจืืคื ืืื. ืืื ืืึธื ืืึธ ืืึธืจื ืืฉื ืฆื ืืืื ืกืคึผืขืฆืืขื ืฉืืึธืืฅ. ืืื ืืึธื ื ืึธืจ ืืขื ืืืขื ืึท ืคืึทืจืืืง ืืืึทืฉืคึผืื ืคืื
from nornir import InitNornir
from nornir.plugins.tasks import networking, text
from nornir.plugins.functions.text import print_title, print_result
def config_and_deploy(task):
# Transform inventory data to configuration via a template file
r = task.run(task=text.template_file,
name="Base Configuration",
template="base.j2",
path=f"templates/{task.host.platform}")
# Save the compiled configuration into a host variable
task.host["config"] = r.result
# Save the compiled configuration into a file
with open(f"configs/{task.host.hostname}", "w") as f:
f.write(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"])
nr = InitNornir(config_file="config.yaml", dry_run=True) # set dry_run=False, cross your fingers and run again
# run tasks
result = nr.run(task=config_and_deploy)
print_result(result)
ืืึทืฆืึธืื ืืคืืขืจืงืืึทืืงืืึทื ืฆื ืื ืคึผืึทืจืึทืืขืืขืจ dry_run=ืืืช ืื ืืืืึทืืืืึทืืืึธื ืืื ืฉืืจื ืืืืคืขืฅ nr.
ืืึธ ืื ืืขืืืข ืืื ืืื ืึทื ืกืึทืืืข ืึท ืคึผืจืึธืืข ืืืืคื ืืื ืืืคึผืืึทืืขื ืึทื ืืื ืืืึธืก ืึท ืงืฉืจ ืฆื ืื ืจืึทืืืขืจ ืืื ืืขืืืื, ืึท ื ืืึทืข ืืึทืืึทืคืืื ืงืึทื ืคืืืืขืจืืืฉืึทื ืืื ืฆืืืขืืจืืื, ืืืึธืก ืืื ืืึทื ืืืึทืืึทืืืืืึทื ืืืจื ืื ืืืื (ืึธืืขืจ ืืึธืก ืืื ื ืืฉื ืืืืขืจ; ืขืก ืืขืคึผืขื ืืก ืืืืฃ ืื ืฉืืืฆื ืคืื ืื ืืืื ืืื ืื ืืืคึผืืึทืืขื ืืืืฉืึทื ืคืื ืื ืืจืืืืืขืจ ืืื NAPALM) , ืึธืืขืจ ืื ื ืืึทืข ืงืึทื ืคืืืืขืจืืืฉืึทื ืืื ื ืืฉื ืืืืึทื ืืขืืืขื ืื. ืคึฟืึทืจ ืงืึทืืืึทื ื ืืฆื, ืืืจ ืืืื ืึทืจืึธืคึผื ืขืืขื ืืขื ืคึผืึทืจืึทืืขืืขืจ dry_run ืึธืืขืจ ืืืืฉื ืืืึทื ืืืขืจื ืฆื ืคืึทืืฉ.
ืืืขื ืืขืจ ืฉืจืืคื ืืื ืขืงืกืึทืงืืืืึทื, Nornir ืึทืืืคึผืืฅ ืืืืืืื ืืึธืืก ืฆื ืื ืงืึทื ืกืึธืื.
ืื ืืขืจ ืืขืจ ืกืคึผืืืืขืจ ืืื ืืขืจ ืจืขืืืืืึทื ืคืื ืึท ืงืึทืืืึทื ืืืืคื ืืืืฃ ืฆืืืื ืคึผืจืืืืจื ืจืึธืืืขืจืก:
config_and_deploy***************************************************************
* cisco-test ** changed : True *******************************************
vvvv config_and_deploy ** changed : True vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
---- Base Configuration ** changed : True ------------------------------------- INFO
class-map match-all VIDEO_SURV
match access-group 111
policy-map VIDEO_SURV
class VIDEO_SURV
police 1500000 conform-action transmit exceed-action drop
interface GigabitEthernet0/1/1
description VIDEOSURV
ip address 10.10.222.254 255.255.255.0
service-policy input VIDEO_SURV
router bgp 65001
network 10.10.222.0 mask 255.255.255.0
access-list 11 permit 10.10.222.0 0.0.0.255
access-list 111 permit ip 10.10.222.0 0.0.0.255 any
---- Loading Configuration on the device ** changed : True --------------------- INFO
+class-map match-all VIDEO_SURV
+ match access-group 111
+policy-map VIDEO_SURV
+ class VIDEO_SURV
+interface GigabitEthernet0/1/1
+ description VIDEOSURV
+ ip address 10.10.222.254 255.255.255.0
+ service-policy input VIDEO_SURV
+router bgp 65001
+ network 10.10.222.0 mask 255.255.255.0
+access-list 11 permit 10.10.222.0 0.0.0.255
+access-list 111 permit ip 10.10.222.0 0.0.0.255 any
^^^^ END config_and_deploy ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* srx-test ** changed : True *******************************************
vvvv config_and_deploy ** changed : True vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
---- Base Configuration ** changed : True ------------------------------------- INFO
set interfaces fe-0/0/2 unit 0 description "Video surveillance"
set interfaces fe-0/0/2 unit 0 family inet filter input limit-in
set interfaces fe-0/0/2 unit 0 family inet address 10.10.111.254/24
set policy-options policy-statement export2bgp term 1 from route-filter 10.10.111.0/24 exact
set security zones security-zone WAN interfaces fe-0/0/2
set firewall policer policer-1m if-exceeding bandwidth-limit 1m
set firewall policer policer-1m if-exceeding burst-size-limit 187k
set firewall policer policer-1m then discard
set firewall policer policer-1.5m if-exceeding bandwidth-limit 1500000
set firewall policer policer-1.5m if-exceeding burst-size-limit 280k
set firewall policer policer-1.5m then discard
set firewall filter limit-in term 1 then policer policer-1.5m
set firewall filter limit-in term 1 then count limiter
---- Loading Configuration on the device ** changed : True --------------------- INFO
[edit interfaces]
+ fe-0/0/2 {
+ unit 0 {
+ description "Video surveillance";
+ family inet {
+ filter {
+ input limit-in;
+ }
+ address 10.10.111.254/24;
+ }
+ }
+ }
[edit]
+ policy-options {
+ policy-statement export2bgp {
+ term 1 {
+ from {
+ route-filter 10.10.111.0/24 exact;
+ }
+ }
+ }
+ }
[edit security zones]
security-zone test-vpn { ... }
+ security-zone WAN {
+ interfaces {
+ fe-0/0/2.0;
+ }
+ }
[edit]
+ firewall {
+ policer policer-1m {
+ if-exceeding {
+ bandwidth-limit 1m;
+ burst-size-limit 187k;
+ }
+ then discard;
+ }
+ policer policer-1.5m {
+ if-exceeding {
+ bandwidth-limit 1500000;
+ burst-size-limit 280k;
+ }
+ then discard;
+ }
+ filter limit-in {
+ term 1 {
+ then {
+ policer policer-1.5m;
+ count limiter;
+ }
+ }
+ }
+ }
^^^^ END config_and_deploy ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ืืึทืืึทืืื ืคึผืึทืกืืืขืจืื ืืื ansible_vault
ืืื ืื ืึธื ืืืื ืคืื ืืขื ืึทืจืืืงื ืืื ืืขืืื ืืขื ืึท ืืืกื ืึธืืืืขืจืืึธืจื ืึทื ืกืึทืืืข, ืึธืืขืจ ืขืก ืืื ื ืืฉื ืึทืืข ืึทื ืฉืืขืื. ืืื ืืึทืงืข ืืื ืืื ืืืึธืื ืืื, ืืืึธืก ืืื ืืืืืื ื ืฆื ืืึทืืึทืืื ืฉืคึผืืจืขืืืืืง ืืื ืคึฟืึธืจืืึทืฆืืข ืืืืก ืคืื ืืขืจืืขื. ืืื ืืืกืืึธืืข ืคืืืข ืืึธืื ืืืืขืจืงื ืึทื ืืืจ ืืึธืื ืึทืืข ืื ืืึธืืื ืก / ืคึผืึทืกืืืขืจืื ืคึฟืึทืจ ืึทืืข ืงืึทืืืึทื ืจืึธืืืขืจืก ืกืคึผืึทืจืงืืื ื ืืื ืึธืคึฟื ืคืึธืจืขื ืืื ืึท ืืขืงืข gorups.yaml. ืขืก ืืื ื ืืฉื ืฉืืื, ืคืื ืงืืจืก. ืืื ืก ืืึทืฉืืฆื ืืขื ืืึทืื ืืื ืืืึธืื.
ืืึธืืืจ ืึทืจืืืขืจืคืืจื ืื ืคึผืึทืจืึทืืขืืขืจืก ืคืื groups.yaml ืฆื creds.yaml ืืื ืื ืงืจืืคึผื ืขืก ืืื AES256 ืืื ืึท 20-ืฆืืคึฟืขืจ ืคึผืึทืจืึธื:
$ cd inventory
$ cat creds.yaml
---
cisco:
username: admin1
password: cisco1
juniper:
username: admin2
password: juniper2
$ pwgen 20 -N 1 > vault.passwd
ansible-vault encrypt creds.yaml --vault-password-file vault.passwd
Encryption successful
$ cat creds.yaml
$ANSIBLE_VAULT;1.1;AES256
39656463353437333337356361633737383464383231366233386636333965306662323534626131
3964396534396333363939373539393662623164373539620a346565373439646436356438653965
39643266333639356564663961303535353364383163633232366138643132313530346661316533
6236306435613132610a656163653065633866626639613537326233653765353661613337393839
62376662303061353963383330323164633162386336643832376263343634356230613562643533
30363436343465306638653932366166306562393061323636636163373164613630643965636361
34343936323066393763323633336366366566393236613737326530346234393735306261363239
35663430623934323632616161636330353134393435396632663530373932383532316161353963
31393434653165613432326636616636383665316465623036376631313162646435
ืขืก ืก ืึทื ืคึผืฉืื. ืขืก ืืืืืื ืฆื ืืขืจื ืขื ืืื ืืืขืจ ื ืึธืจื ืืจ-ืฉืจืืคื ืฆื ืฆืืจืืงืงืจืืื ืืื ืฆืืืืืื ืืขื ืืึทืื.
ืฆื ืืึธื ืืึธืก, ืืื ืืื ืืืขืจ ืฉืจืืคื ื ืึธื ืื ืื ืืืืึทืืืืึทืืืึธื ืฉืืจื nr = InitNornir(config_file =... ืืืื ืื ืคืืืืขื ืืข ืงืึธื:
...
nr = InitNornir(config_file="config.yaml", dry_run=True) # set dry_run=False, cross your fingers and run again
# enrich Inventory with the encrypted vault data
from ansible_vault import Vault
vault_password_file="inventory/vault.passwd"
vault_file="inventory/creds.yaml"
with open(vault_password_file, "r") as fp:
password = fp.readline().strip()
vault = Vault(password)
vaultdata = vault.load(open(vault_file).read())
for a in nr.inventory.hosts.keys():
item = nr.inventory.hosts[a]
item.username = vaultdata[item.groups[0]]['username']
item.password = vaultdata[item.groups[0]]['password']
#print("hostname={}, username={}, password={}n".format(item.hostname, item.username, item.password))
# run tasks
...
ืคืื ืงืืจืก, vault.passwd ืืึธื ื ืื ืืืื ืืืื ืืืืึทืืขืจ ืฆื creds.yaml ืืื ืืื ืืืื ืืืึทืฉืคึผืื. ืืืขืจ ืขืก ืืื ืืื ืคึฟืึทืจ ืคึผืืืืื ื.
ืึทื ืก ืึทืืข ืคึฟืึทืจ ืืืฆื. ืขืก ืืขื ืขื ืึท ืคึผืึธืจ ืืขืจ ืึทืจืืืงืืขื ืืืขืื Cisco + Zabbix ืงืืืขื, ืึธืืขืจ ืืึธืก ืืื ื ืืฉื ืึท ืืืกื ืืืขืื ืึธืืึทืืืืฉืึทื. ืืื ืืื ืืขื ืืขืื ืฆืืงืื ืคึฟื ืืื ืคึผืืึทื ืฆื ืฉืจืืึทืื ืืืขืื RESTCONF ืืื ืกืืกืงืึธ.
ืืงืืจ: www.habr.com