项目作者: JNPRAutomate

项目描述 :
Manage netbox configuration with automation. Netbox as a the source of truth: generate an ansible inventory file from Netbox with automation, generate yaml files for ansible playbooks or jinja templates from Netbox with automation
高级语言: Python
项目地址: git://github.com/JNPRAutomate/netbox_automation.git
创建时间: 2018-05-02T14:57:09Z
项目社区:https://github.com/JNPRAutomate/netbox_automation

开源协议:MIT License

下载


Documentation structure

About Netbox
About this repo
How to use this repo
Netbox Installation
install the requirements to use the automation content hosted in this repository
clone this repository
Define your variables
Configure Netbox with automation
Generate the ansible inventory from Netbox API
Generate yaml files for Jinja templates or ansible playbooks from Netbox API
Use the yaml files generated from the Netbox API
Delete Netbox configuration with automation

About Netbox

Netbox is a popular open source IP address management (IPAM) and data center infrastructure management (DCIM) tool maintained by Jeremy Stretch.

Netbox has RESTful API. The NetBox API represents all objects in JSON.
There is a NAPALM integration to pull some data from devices for validation purpose.

Here’s the doc
Here’s the code

About this repo

Netbox is supposed to be the source of truth for the the assets it manages:

So this new repo is about:

  • Netbox configuration with automation (with a focus on Juniper devices)
  • ansible inventory file generated with automation from Netbox API
  • yaml files (variables) for Jinja templates or ansible playbooks generated with automation from Netbox API

This repository doesn’t install Netbox. You still need to install Netbox yourself.

This repository has been tested using:

  • Ubuntu 16.04
  • Python 2.7
  • Netbox v2.2.9

How to use this repo

The steps are:

  • Install Netbox.
    • This repository doesn’t install Netbox. You still need to install Netbox yourself.
  • Install the requirements to use the python scripts hosted in this repository
  • Clone this repository
  • Edit the file variables.yml to indicate what you want to configure on Netbox
  • To configure Netbox, execute the script configure_netbox.py.
    • It uses the variables defined in the file variables.yml and configures Netbox
  • To generate an Ansible inventory file from Netbox API, execute the script ansible_dynamic_inventory.py
  • To generate yaml files for jinja templates and ansible playbooks from Netbox API, execute the script generate_vars_for_jinja_from_netbox.py
  • To delete Netbox configuration, execute the script delete_netbox_configuration.py

Netbox Installation

See the installation guide
This repository has been tested with Netbox version v2.2.9

Once netbox is installed, you can use it:

This repository uses Netbox REST API. So you need to create a Netbox API Token.

install the requirements to use the automation content hosted in this repository

The python scripts hosted in this repository use the library requests to make REST calls to Netbox.
Run these commands on your laptop:

  1. sudo -s
  2. pip install requests

clone this repository

Run these commands on your laptop:

  1. sudo -s
  2. git clone https://github.com/JNPRAutomate/netbox_automation.git
  3. cd netbox_automation

Define your variables

The file variables.yml defines variables.
On your laptop, edit it to indicate details such as:

  • The IP address of your Netbox server
  • The Netbox user token you want to use
  • The Netbox details you want to configure with automation:
    • a tenant
    • sites
    • device-roles
    • devices
    • prefixes-roles
    • prefixes
    • device management ip addresses
    • ip addresses to assign to devices interfaces
    • interface connections (physical topology)
    • In addition to this, there are others Netbox details that will be configured automatically:
      • device-types (Juniper qfx5100-48s-6q and qfx10002-36q)
      • a platform (Junos platform with a junos napalm_driver)

Run these commands on your laptop:

  1. vi variable.yml
  1. $ more variables.yml
  2. ---
  3. # Edit this file to define the details to configure on Netbox
  4. # netbox server ip @
  5. ip: 192.168.233.152
  6. # netbox user token you want to use
  7. token: 'b1b0f72bed6946d352b78781030e8d626f5e8c28'
  8. # netbox tenants you want to create. please create one single tenant.
  9. tenants:
  10. - evpn-vxlan-demo
  11. # netbox sites you want to create. the sites are assigned to the tenant.
  12. sites:
  13. - dc1
  14. - dc2
  15. # netbox device-roles you want to create
  16. device-roles:
  17. - "spine_switch"
  18. - "leaf_switch"
  19. # device-types qfx5100-48s-6q and qfx10002-36q are automatically created.
  20. # interface_templates are automatically created for device-types qfx5100-48s-6q and qfx10002-36q
  21. # power_port_templates are automatically created for device-types qfx5100-48s-6q and qfx10002-36q
  22. # Juniper Junos platform is automatically created with a junos napalm_driver
  23. # prefix roles you want to create
  24. prefix_roles:
  25. - out_of_band_management
  26. - devices_interconnection
  27. # prefixes you want to create.
  28. # These prefixes are assigned to the tenant.
  29. prefixes:
  30. - prefix: 10.0.2.0/24
  31. role: devices_interconnection
  32. - prefix: 172.25.90.0/24
  33. role: out_of_band_management
  34. # devices you want to create. the devices are assigned to the tenant.
  35. devices:
  36. - name: QFX5100-183
  37. device_type: qfx5100-48s-6q
  38. device_role: leaf_switch
  39. site: dc1
  40. - name: QFX5100-186
  41. device_type: qfx5100-48s-6q
  42. device_role: leaf_switch
  43. site: dc1
  44. - name: QFX10K2-178
  45. device_type: qfx10002-36q
  46. device_role: spine_switch
  47. site: dc1
  48. - name: QFX10K2-180
  49. device_type: qfx10002-36q
  50. device_role: spine_switch
  51. site: dc1
  52. - name: QFX10K2-181
  53. device_type: qfx10002-36q
  54. device_role: spine_switch
  55. site: dc1
  56. - name: QFX10K2-174
  57. device_type: qfx10002-36q
  58. device_role: spine_switch
  59. site: dc2
  60. - name: QFX10K2-175
  61. device_type: qfx10002-36q
  62. device_role: spine_switch
  63. site: dc2
  64. # management ip addresses you want to create. The IP addresses are assigned to the tenant.
  65. management_addresses:
  66. - ip: 172.25.90.183
  67. device: QFX5100-183
  68. interface: vme0
  69. mgmt_only: True
  70. - ip: 172.25.90.186
  71. device: QFX5100-186
  72. interface: vme0
  73. mgmt_only: True
  74. - ip: 172.25.90.178
  75. device: QFX10K2-178
  76. interface: em0
  77. mgmt_only: True
  78. - ip: 172.25.90.174
  79. device: QFX10K2-174
  80. interface: em0
  81. mgmt_only: True
  82. - ip: 172.25.90.175
  83. device: QFX10K2-175
  84. interface: em0
  85. mgmt_only: True
  86. - ip: 172.25.90.180
  87. device: QFX10K2-180
  88. interface: em0
  89. mgmt_only: True
  90. - ip: 172.25.90.181
  91. device: QFX10K2-181
  92. interface: em0
  93. mgmt_only: True
  94. # Other ip addresses you want to create. The IP addresses are assigned to the tenant.
  95. ip_addresses:
  96. - ip: 10.0.2.13/31
  97. device: QFX10K2-180
  98. interface: et-0/0/0
  99. - ip: 10.0.2.23/31
  100. device: QFX10K2-180
  101. interface: et-0/0/1
  102. - ip: 10.0.2.15/31
  103. device: QFX10K2-181
  104. interface: et-0/0/0
  105. - ip: 10.0.2.25/31
  106. device: QFX10K2-181
  107. interface: et-0/0/1
  108. - ip: 10.0.2.9/31
  109. device: QFX10K2-178
  110. interface: et-0/0/0
  111. - ip: 10.0.2.19/31
  112. device: QFX10K2-178
  113. interface: et-0/0/1
  114. # define how the interfaces are connected (physical topology).
  115. interface_connections:
  116. - device_a: QFX5100-183
  117. interface_a: et-0/0/48
  118. device_b: QFX10K2-178
  119. interface_b: et-0/0/2
  120. connection_status: Connected
  121. - device_a: QFX10K2-181
  122. interface_a: et-0/0/3
  123. device_b: QFX5100-186
  124. interface_b: et-0/0/49
  125. connection_status: Connected

Configure Netbox with automation

The script configure_netbox.py configures Netbox using the file variables.yml

  1. $ python configure_netbox.py
  2. device role spine_switch successfully created
  3. device role leaf_switch successfully created
  4. tenant evpn-vxlan-demo successfully created
  5. site dc1 successfully created
  6. site dc2 successfully created
  7. device type qfx5100-48s-6q successfully created
  8. device type qfx10002-36q successfully created
  9. prefix role out_of_band_management successfully created
  10. prefix role devices_interconnection successfully created
  11. prefix 10.0.2.0/24 successfully created
  12. prefix 172.25.90.0/24 successfully created
  13. platform junos with a junos napalm_driver successfully created
  14. device QFX5100-183 successfully created
  15. device QFX5100-186 successfully created
  16. device QFX10K2-178 successfully created
  17. device QFX10K2-180 successfully created
  18. device QFX10K2-181 successfully created
  19. device QFX10K2-174 successfully created
  20. device QFX10K2-175 successfully created
  21. address ip 172.25.90.183 successfully created
  22. address ip 172.25.90.186 successfully created
  23. address ip 172.25.90.178 successfully created
  24. address ip 172.25.90.174 successfully created
  25. address ip 172.25.90.175 successfully created
  26. address ip 172.25.90.180 successfully created
  27. address ip 172.25.90.181 successfully created
  28. address ip 10.0.2.13/31 successfully created
  29. address ip 10.0.2.23/31 successfully created
  30. address ip 10.0.2.15/31 successfully created
  31. address ip 10.0.2.25/31 successfully created
  32. address ip 10.0.2.9/31 successfully created
  33. address ip 10.0.2.19/31 successfully created
  34. interface connection between QFX5100-183 et-0/0/48 and QFX10K2-178 et-0/0/2 successfully created
  35. interface connection between QFX10K2-181 et-0/0/3 and QFX5100-186 et-0/0/49 successfully created

Generate the ansible inventory from Netbox API

The script ansible_dynamic_inventory.py generates the ansible inventory hosts from Netbox API

  1. $ python ansible_dynamic_inventory.py
  1. $ more hosts
  2. #Ansible dynamic inventory file generated from Netbox API
  3. [juniper:children]
  4. qfx10002-36q
  5. qfx5100-48s-6q
  6. [qfx10002-36q]
  7. QFX10K2-174 junos_host=172.25.90.174
  8. QFX10K2-175 junos_host=172.25.90.175
  9. QFX10K2-178 junos_host=172.25.90.178
  10. QFX10K2-180 junos_host=172.25.90.180
  11. QFX10K2-181 junos_host=172.25.90.181
  12. [qfx5100-48s-6q]
  13. QFX5100-183 junos_host=172.25.90.183
  14. QFX5100-186 junos_host=172.25.90.186
  15. [dc1]
  16. [QFX10K2-178]
  17. [QFX10K2-180]
  18. [QFX10K2-181]
  19. [QFX5100-183]
  20. [QFX5100-186]
  21. [dc2]
  22. [QFX10K2-174]
  23. [QFX10K2-175]
  24. [leaf_switch]
  25. [QFX5100-183]
  26. [QFX5100-186]
  27. [spine_switch]
  28. [QFX10K2-174]
  29. [QFX10K2-175]
  30. [QFX10K2-178]
  31. [QFX10K2-180]
  32. [QFX10K2-181]

The playbook pb_print_junos_facts.yml has been tested with ansible 2.4.2.0.
It uses the ansible inventory file generated from Netbox API.

Run these commands on Ubuntu 16.04 to install Ansible and its requirements for Junos:

  1. sudo -s
  2. apt-get update
  3. apt-get install -y python-dev libxml2-dev python-pip libxslt1-dev build-essential libssl-dev libffi-dev git
  4. pip install junos-eznc jxmlease wget ansible==2.4.2.0 requests ipaddress cryptography
  1. # ansible-playbook pb_print_junos_facts.yml
  2. PLAY [Get Facts] ********************************************************************************************************************************************************
  3. TASK [Retrieve information from devices running Junos] ******************************************************************************************************************
  4. ok: [QFX10K2-178]
  5. ok: [QFX10K2-180]
  6. ok: [QFX10K2-174]
  7. ok: [QFX10K2-175]
  8. ok: [QFX10K2-181]
  9. ok: [QFX5100-183]
  10. ok: [QFX5100-186]
  11. TASK [Print some facts] *************************************************************************************************************************************************
  12. ok: [QFX10K2-174] => {
  13. "msg": "device QFX10K2-174 is a qfx10002-36q running junos version 17.4R1-S1.9"
  14. }
  15. ok: [QFX10K2-175] => {
  16. "msg": "device QFX10K2-175 is a qfx10002-36q running junos version 17.4R1-S1.9"
  17. }
  18. ok: [QFX10K2-178] => {
  19. "msg": "device QFX10K2-178 is a qfx10002-36q running junos version 17.4R1-S1.9"
  20. }
  21. ok: [QFX10K2-180] => {
  22. "msg": "device QFX10K2-180 is a qfx10002-36q running junos version 17.4R1-S1.9"
  23. }
  24. ok: [QFX10K2-181] => {
  25. "msg": "device QFX10K2-181 is a qfx10002-36q running junos version 17.4R1-S1.9"
  26. }
  27. ok: [QFX5100-183] => {
  28. "msg": "device QFX5100-183 is a qfx5100-48s-6q running junos version 17.4R1-S1.9"
  29. }
  30. ok: [QFX5100-186] => {
  31. "msg": "device QFX5100-186 is a qfx5100-48s-6q running junos version 17.4R1-S1.9"
  32. }
  33. PLAY RECAP **************************************************************************************************************************************************************
  34. QFX10K2-174 : ok=2 changed=0 unreachable=0 failed=0
  35. QFX10K2-175 : ok=2 changed=0 unreachable=0 failed=0
  36. QFX10K2-178 : ok=2 changed=0 unreachable=0 failed=0
  37. QFX10K2-180 : ok=2 changed=0 unreachable=0 failed=0
  38. QFX10K2-181 : ok=2 changed=0 unreachable=0 failed=0
  39. QFX5100-183 : ok=2 changed=0 unreachable=0 failed=0
  40. QFX5100-186 : ok=2 changed=0 unreachable=0 failed=0
  1. # ansible-playbook pb_print_junos_facts.yml --limit QFX10K2-180
  2. PLAY [Get Facts] ********************************************************************************************************************************************************
  3. TASK [Retrieve information from devices running Junos] ******************************************************************************************************************
  4. ok: [QFX10K2-180]
  5. TASK [Print some facts] *************************************************************************************************************************************************
  6. ok: [QFX10K2-180] => {
  7. "msg": "device QFX10K2-180 is a qfx10002-36q running junos version 17.4R1-S1.9"
  8. }
  9. PLAY RECAP **************************************************************************************************************************************************************
  10. QFX10K2-180 : ok=2 changed=0 unreachable=0 failed=0
  1. # ansible-playbook pb_print_junos_facts.yml --limit dc2
  2. PLAY [Get Facts] ********************************************************************************************************************************************************
  3. TASK [Retrieve information from devices running Junos] ******************************************************************************************************************
  4. ok: [QFX10K2-174]
  5. ok: [QFX10K2-175]
  6. TASK [Print some facts] *************************************************************************************************************************************************
  7. ok: [QFX10K2-174] => {
  8. "msg": "device QFX10K2-174 is a qfx10002-36q running junos version 17.4R1-S1.9"
  9. }
  10. ok: [QFX10K2-175] => {
  11. "msg": "device QFX10K2-175 is a qfx10002-36q running junos version 17.4R1-S1.9"
  12. }
  13. PLAY RECAP **************************************************************************************************************************************************************
  14. QFX10K2-174 : ok=2 changed=0 unreachable=0 failed=0
  15. QFX10K2-175 : ok=2 changed=0 unreachable=0 failed=0
  1. # ansible-playbook pb_print_junos_facts.yml --limit spine_switch
  2. PLAY [Get Facts] ********************************************************************************************************************************************************
  3. TASK [Retrieve information from devices running Junos] ******************************************************************************************************************
  4. ok: [QFX10K2-180]
  5. ok: [QFX10K2-175]
  6. ok: [QFX10K2-174]
  7. ok: [QFX10K2-178]
  8. ok: [QFX10K2-181]
  9. TASK [Print some facts] *************************************************************************************************************************************************
  10. ok: [QFX10K2-174] => {
  11. "msg": "device QFX10K2-174 is a qfx10002-36q running junos version 17.4R1-S1.9"
  12. }
  13. ok: [QFX10K2-175] => {
  14. "msg": "device QFX10K2-175 is a qfx10002-36q running junos version 17.4R1-S1.9"
  15. }
  16. ok: [QFX10K2-178] => {
  17. "msg": "device QFX10K2-178 is a qfx10002-36q running junos version 17.4R1-S1.9"
  18. }
  19. ok: [QFX10K2-180] => {
  20. "msg": "device QFX10K2-180 is a qfx10002-36q running junos version 17.4R1-S1.9"
  21. }
  22. ok: [QFX10K2-181] => {
  23. "msg": "device QFX10K2-181 is a qfx10002-36q running junos version 17.4R1-S1.9"
  24. }
  25. PLAY RECAP **************************************************************************************************************************************************************
  26. QFX10K2-174 : ok=2 changed=0 unreachable=0 failed=0
  27. QFX10K2-175 : ok=2 changed=0 unreachable=0 failed=0
  28. QFX10K2-178 : ok=2 changed=0 unreachable=0 failed=0
  29. QFX10K2-180 : ok=2 changed=0 unreachable=0 failed=0
  30. QFX10K2-181 : ok=2 changed=0 unreachable=0 failed=0
  1. # ansible-playbook pb_print_junos_facts.yml --limit qfx5100-48s-6q
  2. PLAY [Get Facts] ********************************************************************************************************************************************************
  3. TASK [Retrieve information from devices running Junos] ******************************************************************************************************************
  4. ok: [QFX5100-183]
  5. ok: [QFX5100-186]
  6. TASK [Print some facts] *************************************************************************************************************************************************
  7. ok: [QFX5100-183] => {
  8. "msg": "device QFX5100-183 is a qfx5100-48s-6q running junos version 17.4R1-S1.9"
  9. }
  10. ok: [QFX5100-186] => {
  11. "msg": "device QFX5100-186 is a qfx5100-48s-6q running junos version 17.4R1-S1.9"
  12. }
  13. PLAY RECAP **************************************************************************************************************************************************************
  14. QFX5100-183 : ok=2 changed=0 unreachable=0 failed=0
  15. QFX5100-186 : ok=2 changed=0 unreachable=0 failed=0

Generate yaml files for Jinja templates or ansible playbooks from Netbox API

The script generate_vars_for_jinja_from_netbox.py generates yaml files for jinja templates and ansible playbooks from Netbox API.

There is no variable available:

  1. # ls host_vars
  2. ls: cannot access 'host_vars': No such file or directory

Generate the variables:

  1. # python generate_vars_for_jinja_from_netbox.py
  1. # ls host_vars
  2. QFX10K2-174 QFX10K2-175 QFX10K2-178 QFX10K2-180 QFX10K2-181 QFX5100-183 QFX5100-186
  1. # more host_vars/QFX10K2-181/vars_from_netbox_api.yml
  2. vars_from_netbox_api:
  3. - address: 10.0.2.15/31
  4. interface: et-0/0/0
  5. - address: 10.0.2.25/31
  6. interface: et-0/0/1
  7. - address: 172.25.90.181/32
  8. interface: em0
  1. # more host_vars/QFX10K2-178/vars_from_netbox_api.yml
  2. vars_from_netbox_api:
  3. - address: 10.0.2.9/31
  4. interface: et-0/0/0
  5. - address: 10.0.2.19/31
  6. interface: et-0/0/1
  7. - address: 172.25.90.178/32
  8. interface: em0

Use the yaml files generated from the Netbox API

The playbook pb_check_interfaces.yml uses:

  • the ansible inventory we generated from Netbox API
  • the variables we generated from Netbox API
  1. # ansible-playbook pb_check_interfaces.yml
  2. PLAY [check interface states] *******************************************************************************************************************************************
  3. TASK [check if interfaces admin status is up] ***************************************************************************************************************************
  4. ok: [QFX10K2-174] => (item={u'interface': u'em0', u'address': u'172.25.90.174/32'})
  5. ok: [QFX10K2-175] => (item={u'interface': u'em0', u'address': u'172.25.90.175/32'})
  6. ok: [QFX10K2-180] => (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.13/31'})
  7. ok: [QFX10K2-178] => (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.9/31'})
  8. ok: [QFX10K2-181] => (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.15/31'})
  9. ok: [QFX10K2-180] => (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.23/31'})
  10. ok: [QFX10K2-181] => (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.25/31'})
  11. ok: [QFX10K2-178] => (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.19/31'})
  12. ok: [QFX10K2-180] => (item={u'interface': u'em0', u'address': u'172.25.90.180/32'})
  13. ok: [QFX10K2-181] => (item={u'interface': u'em0', u'address': u'172.25.90.181/32'})
  14. ok: [QFX10K2-178] => (item={u'interface': u'em0', u'address': u'172.25.90.178/32'})
  15. TASK [check if interfaces op status is up] ******************************************************************************************************************************
  16. ok: [QFX10K2-174] => (item={u'interface': u'em0', u'address': u'172.25.90.174/32'})
  17. ok: [QFX10K2-175] => (item={u'interface': u'em0', u'address': u'172.25.90.175/32'})
  18. ok: [QFX10K2-178] => (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.9/31'})
  19. ok: [QFX10K2-181] => (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.15/31'})
  20. ok: [QFX10K2-180] => (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.13/31'})
  21. ok: [QFX10K2-178] => (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.19/31'})
  22. ok: [QFX10K2-180] => (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.23/31'})
  23. ok: [QFX10K2-181] => (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.25/31'})
  24. ok: [QFX10K2-178] => (item={u'interface': u'em0', u'address': u'172.25.90.178/32'})
  25. ok: [QFX10K2-180] => (item={u'interface': u'em0', u'address': u'172.25.90.180/32'})
  26. ok: [QFX10K2-181] => (item={u'interface': u'em0', u'address': u'172.25.90.181/32'})
  27. PLAY RECAP **************************************************************************************************************************************************************
  28. QFX10K2-174 : ok=2 changed=0 unreachable=0 failed=0
  29. QFX10K2-175 : ok=2 changed=0 unreachable=0 failed=0
  30. QFX10K2-178 : ok=2 changed=0 unreachable=0 failed=0
  31. QFX10K2-180 : ok=2 changed=0 unreachable=0 failed=0
  32. QFX10K2-181 : ok=2 changed=0 unreachable=0 failed=0

The playbook pb_render_template.yml renders the template template.j2 using the yaml files built from Netbox API. It saves the generated files in the directory render.

  1. # more pb_render_template.yml
  2. ---
  3. - name: create a directory
  4. hosts: localhost
  5. gather_facts: no
  6. tasks:
  7. - name: create the directory render
  8. file:
  9. path: "{{playbook_dir}}/render"
  10. state: directory
  11. - name: render junos configuration template using vars from Netbox API
  12. hosts: juniper
  13. connection: local
  14. gather_facts: no
  15. tasks:
  16. - name: render junos configuration template using vars from Netbox API
  17. template:
  18. src: "{{ playbook_dir }}/template.j2"
  19. dest: "{{ playbook_dir }}/render/{{ inventory_hostname }}.conf"
  1. # more template.j2
  2. interfaces {
  3. {% for item in vars_from_netbox_api %}
  4. {{ item.interface }} {
  5. unit 0 {
  6. family inet {
  7. address {{ item.address }};
  8. }
  9. }
  10. }
  11. {% endfor %}
  12. }
  13. protocols {
  14. lldp {
  15. {% for item in vars_from_netbox_api %}
  16. interface "{{ item.interface }}";
  17. {% endfor %}
  18. }
  19. }
  1. # ls render
  2. ls: cannot access 'render': No such file or directory
  1. # ansible-playbook pb_render_template.yml
  2. PLAY [create a directory] ***********************************************************************************************************************************************
  3. TASK [create the directory render] **************************************************************************************************************************************
  4. changed: [localhost]
  5. PLAY [render junos configuration template using vars from Netbox API] ***************************************************************************************************
  6. TASK [render junos configuration template using vars from Netbox API] ***************************************************************************************************
  7. changed: [QFX10K2-181]
  8. changed: [QFX10K2-174]
  9. changed: [QFX10K2-180]
  10. changed: [QFX10K2-175]
  11. changed: [QFX10K2-178]
  12. changed: [QFX5100-183]
  13. changed: [QFX5100-186]
  14. PLAY RECAP **************************************************************************************************************************************************************
  15. QFX10K2-174 : ok=1 changed=1 unreachable=0 failed=0
  16. QFX10K2-175 : ok=1 changed=1 unreachable=0 failed=0
  17. QFX10K2-178 : ok=1 changed=1 unreachable=0 failed=0
  18. QFX10K2-180 : ok=1 changed=1 unreachable=0 failed=0
  19. QFX10K2-181 : ok=1 changed=1 unreachable=0 failed=0
  20. QFX5100-183 : ok=1 changed=1 unreachable=0 failed=0
  21. QFX5100-186 : ok=1 changed=1 unreachable=0 failed=0
  22. localhost : ok=1 changed=1 unreachable=0 failed=0
  1. # ls render
  2. QFX10K2-174.conf QFX10K2-175.conf QFX10K2-178.conf QFX10K2-180.conf QFX10K2-181.conf QFX5100-183.conf QFX5100-186.conf
  1. # more render/QFX10K2-181.conf
  2. interfaces {
  3. et-0/0/0 {
  4. unit 0 {
  5. family inet {
  6. address 10.0.2.15/31;
  7. }
  8. }
  9. }
  10. et-0/0/1 {
  11. unit 0 {
  12. family inet {
  13. address 10.0.2.25/31;
  14. }
  15. }
  16. }
  17. em0 {
  18. unit 0 {
  19. family inet {
  20. address 172.25.90.181/32;
  21. }
  22. }
  23. }
  24. }
  25. protocols {
  26. lldp {
  27. interface "et-0/0/0";
  28. interface "et-0/0/1";
  29. interface "em0";
  30. }
  31. }

Delete Netbox configuration with automation

The script delete_netbox_configuration.py delete the Netbox configuration:

  • all tenants
  • all sites
  • all device-roles
  • all device-types
  • all platforms
  • all interface connections
  • all devices
  • all prefixes-roles
  • all prefixes
  • all ip addresses
    1. $ python delete_netbox_configuration.py