{"id":13586686,"url":"https://github.com/ksator/netbox_automation","last_synced_at":"2025-04-07T18:34:29.674Z","repository":{"id":44967798,"uuid":"121358006","full_name":"ksator/netbox_automation","owner":"ksator","description":"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 ","archived":true,"fork":false,"pushed_at":"2018-09-30T18:14:25.000Z","size":75,"stargazers_count":56,"open_issues_count":1,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-02-14T21:40:14.430Z","etag":null,"topics":["ansible","junos-automation","netbox","network-automation","python","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ksator.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-13T08:35:33.000Z","updated_at":"2023-08-08T18:03:30.000Z","dependencies_parsed_at":"2022-07-13T03:30:31.120Z","dependency_job_id":null,"html_url":"https://github.com/ksator/netbox_automation","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksator%2Fnetbox_automation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksator%2Fnetbox_automation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksator%2Fnetbox_automation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksator%2Fnetbox_automation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksator","download_url":"https://codeload.github.com/ksator/netbox_automation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247707760,"owners_count":20982844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","junos-automation","netbox","network-automation","python","rest-api"],"created_at":"2024-08-01T15:05:44.462Z","updated_at":"2025-04-07T18:34:29.359Z","avatar_url":"https://github.com/ksator.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/ksator/netbox_automation.svg?branch=master)](https://travis-ci.org/ksator/netbox_automation)\n\n## Documentation structure\n[**About Netbox**](README.md#about-netbox)  \n[**About this repo**](README.md#about-this-repo)  \n[**How to use this repo**](README.md#how-to-use-this-repo)    \n[**Netbox Installation**](README.md#netbox-installation)  \n[**install the requirements to use the automation content hosted in this repository**](README.md#install-the-requirements-to-use-the-automation-content-hosted-in-this-repository)  \n[**clone this repository**](README.md#clone-this-repository)  \n[**Define your variables**](README.md#define-your-variables)  \n[**Configure Netbox with automation**](README.md#configure-netbox-with-automation)  \n[**Generate the ansible inventory from Netbox API**](README.md#generate-the-ansible-inventory-from-netbox-api)  \n[**Generate yaml files for Jinja templates or ansible playbooks from Netbox API**](README.md#generate-yaml-files-for-jinja-templates-or-ansible-playbooks-from-netbox-api)  \n[**Use the yaml files generated from the Netbox API**](README.md#use-the-yaml-files-generated-from-the-netbox-api)  \n[**Delete Netbox configuration with automation**](README.md#delete-netbox-configuration-with-automation)  \n[**Continuous integration with Travis CI**](README.md#continuous-integration-with-travis-ci)  \n[**Looking for more automation solutions**](README.md#looking-for-more-automation-solutions)  \n\n\n## About Netbox\n\nNetbox is a popular open source IP address management (IPAM) and data center infrastructure management (DCIM) tool maintained by Jeremy Stretch.  \n\nNetbox has RESTful API. The NetBox API represents all objects in JSON.  \nThere is a NAPALM integration to pull some data from devices for validation purpose. \n\nHere's the [doc](https://netbox.readthedocs.io/en/latest/)   \nHere's the [code](https://github.com/digitalocean/netbox)  \n\n## About this repo\n\nNetbox is supposed to be the source of truth for the the assets it manages:\n\nSo this new repo is about: \n-\tNetbox configuration with automation (with a focus on Juniper devices) \n-\tansible inventory file generated with automation from Netbox API   \n-\tyaml files (variables) for Jinja templates or ansible playbooks generated with automation from Netbox API \n\nThis repository doesn’t install Netbox. You still need to install Netbox yourself.\n\nThis repository has been tested using: \n- Ubuntu 16.04\n- Python 2.7\n- Netbox v2.2.9\n    \n## How to use this repo\n\nThe steps are:  \n- Install Netbox. \n   - This repository doesn’t install Netbox. You still need to install Netbox yourself.  \n- Install the requirements to use the python scripts hosted in this repository  \n- Clone this repository\n- Edit the file [**variables.yml**](variables.yml) to indicate what you want to configure on Netbox\n- To configure Netbox, execute the script [**configure_netbox.py**](configure_netbox.py). \n   - It uses the variables defined in the file [**variables.yml**](variables.yml) and configures Netbox \n- To generate an Ansible inventory file from Netbox API, execute the script [**ansible_dynamic_inventory.py**](ansible_dynamic_inventory.py)\n- To generate yaml files for jinja templates and ansible playbooks from Netbox API, execute the script [**generate_vars_for_jinja_from_netbox.py**](generate_vars_for_jinja_from_netbox.py)   \n- To delete Netbox configuration, execute the script [**delete_netbox_configuration.py**](delete_netbox_configuration.py)\n\n## Netbox Installation\nSee the [**installation guide**](http://netbox.readthedocs.io/en/stable/)  \nThis repository has been tested with Netbox version v2.2.9  \n\nOnce netbox is installed, you can use it: \n- netbox GUI http://your_netbox_server\n- netbox API http://your_netbox_server/api/\n- netbox API doc http://your_netbox_server/api/docs/\n\nThis repository uses Netbox REST API. So you need to create a Netbox API Token. \n\n\n## install the requirements to use the automation content hosted in this repository  \nThe python scripts hosted in this repository use the library **requests** to make REST calls to Netbox.   \nRun these commands on your laptop:\n```\nsudo -s\npip install requests\n```\n\n## clone this repository\nRun these commands on your laptop:\n```\nsudo -s\ngit clone https://github.com/ksator/netbox_automation.git \ncd netbox_automation\n```\n\n## Define your variables\n\nThe file [**variables.yml**](variables.yml) defines variables.\nOn your laptop, edit it to indicate details such as:\n- The IP address of your Netbox server\n- The Netbox user token you want to use\n- The Netbox details you want to configure with automation: \n   - a tenant\n   - sites\n   - device-roles\n   - devices\n   - prefixes-roles\n   - prefixes\n   - device management ip addresses\n   - ip addresses to assign to devices interfaces\n   - interface connections (physical topology) \n   - In addition to this, there are others Netbox details that will be configured automatically: \n     - device-types (Juniper qfx5100-48s-6q and qfx10002-36q) \n     - a platform (Junos platform with a junos napalm_driver)\n\nRun these commands on your laptop:\n```\nvi variable.yml\n```\n```\n$ more variables.yml \n---\n# Edit this file to define the details to configure on Netbox\n\n# netbox server ip @\nip: 192.168.233.152\n\n# netbox user token you want to use\ntoken: 'b1b0f72bed6946d352b78781030e8d626f5e8c28'\n\n# netbox tenants you want to create. please create one single tenant.\ntenants: \n    - evpn-vxlan-demo\n\n# netbox sites you want to create. the sites are assigned to the tenant.\nsites:\n    - dc1\n    - dc2\n\n# netbox device-roles you want to create\ndevice-roles: \n    - \"spine_switch\"\n    - \"leaf_switch\"   \n\n# device-types qfx5100-48s-6q and qfx10002-36q are automatically created. \n# interface_templates are automatically created for device-types qfx5100-48s-6q and qfx10002-36q\n# power_port_templates are automatically created for device-types qfx5100-48s-6q and qfx10002-36q\n# Juniper Junos platform is automatically created with a junos napalm_driver\n\n# prefix roles you want to create\nprefix_roles: \n    - out_of_band_management\n    - devices_interconnection\n\n# prefixes you want to create. \n# These prefixes are assigned to the tenant.\nprefixes:\n    - prefix: 10.0.2.0/24\n      role: devices_interconnection\n    - prefix: 172.25.90.0/24\n      role: out_of_band_management\n    \n# devices you want to create. the devices are assigned to the tenant.\ndevices: \n    - name: QFX5100-183\n      device_type: qfx5100-48s-6q\n      device_role: leaf_switch\n      site: dc1\n    - name: QFX5100-186\n      device_type: qfx5100-48s-6q\n      device_role: leaf_switch\n      site: dc1\n    - name: QFX10K2-178\n      device_type: qfx10002-36q\n      device_role: spine_switch\n      site: dc1\n    - name: QFX10K2-180\n      device_type: qfx10002-36q\n      device_role: spine_switch\n      site: dc1\n    - name: QFX10K2-181\n      device_type: qfx10002-36q\n      device_role: spine_switch\n      site: dc1\n    - name: QFX10K2-174\n      device_type: qfx10002-36q\n      device_role: spine_switch\n      site: dc2\n    - name: QFX10K2-175\n      device_type: qfx10002-36q\n      device_role: spine_switch\n      site: dc2\n    \n# management ip addresses you want to create. The IP addresses are assigned to the tenant.\nmanagement_addresses: \n    - ip: 172.25.90.183\n      device: QFX5100-183\n      interface: vme0\n      mgmt_only: True\n    - ip: 172.25.90.186\n      device: QFX5100-186\n      interface: vme0\n      mgmt_only: True\n    - ip: 172.25.90.178\n      device: QFX10K2-178\n      interface: em0\n      mgmt_only: True\n    - ip: 172.25.90.174\n      device: QFX10K2-174\n      interface: em0\n      mgmt_only: True\n    - ip: 172.25.90.175\n      device: QFX10K2-175\n      interface: em0\n      mgmt_only: True\n    - ip: 172.25.90.180\n      device: QFX10K2-180\n      interface: em0\n      mgmt_only: True\n    - ip: 172.25.90.181\n      device: QFX10K2-181\n      interface: em0\n      mgmt_only: True\n\n# Other ip addresses you want to create. The IP addresses are assigned to the tenant.\nip_addresses:\n    - ip: 10.0.2.13/31\n      device: QFX10K2-180\n      interface: et-0/0/0\n    - ip: 10.0.2.23/31\n      device: QFX10K2-180\n      interface: et-0/0/1\n    - ip: 10.0.2.15/31\n      device: QFX10K2-181\n      interface: et-0/0/0\n    - ip: 10.0.2.25/31\n      device: QFX10K2-181\n      interface: et-0/0/1\n    - ip: 10.0.2.9/31\n      device: QFX10K2-178\n      interface: et-0/0/0\n    - ip: 10.0.2.19/31\n      device: QFX10K2-178\n      interface: et-0/0/1\n\n# define how the interfaces are connected (physical topology). \ninterface_connections:\n    - device_a: QFX5100-183\n      interface_a: et-0/0/48\n      device_b: QFX10K2-178\n      interface_b: et-0/0/2\n      connection_status: Connected\n    - device_a: QFX10K2-181\n      interface_a: et-0/0/3\n      device_b: QFX5100-186\n      interface_b: et-0/0/49\n      connection_status: Connected\n```\n## Configure Netbox with automation\n\nThe script [**configure_netbox.py**](configure_netbox.py) configures Netbox using the file [**variables.yml**](variables.yml) \n\n```\n$ python configure_netbox.py \ndevice role spine_switch successfully created\ndevice role leaf_switch successfully created\ntenant evpn-vxlan-demo successfully created\nsite dc1 successfully created\nsite dc2 successfully created\ndevice type qfx5100-48s-6q successfully created\ndevice type qfx10002-36q successfully created\nprefix role out_of_band_management successfully created\nprefix role devices_interconnection successfully created\nprefix 10.0.2.0/24 successfully created\nprefix 172.25.90.0/24 successfully created\nplatform junos with a junos napalm_driver successfully created\ndevice QFX5100-183 successfully created\ndevice QFX5100-186 successfully created\ndevice QFX10K2-178 successfully created\ndevice QFX10K2-180 successfully created\ndevice QFX10K2-181 successfully created\ndevice QFX10K2-174 successfully created\ndevice QFX10K2-175 successfully created\naddress ip 172.25.90.183 successfully created\naddress ip 172.25.90.186 successfully created\naddress ip 172.25.90.178 successfully created\naddress ip 172.25.90.174 successfully created\naddress ip 172.25.90.175 successfully created\naddress ip 172.25.90.180 successfully created\naddress ip 172.25.90.181 successfully created\naddress ip 10.0.2.13/31 successfully created\naddress ip 10.0.2.23/31 successfully created\naddress ip 10.0.2.15/31 successfully created\naddress ip 10.0.2.25/31 successfully created\naddress ip 10.0.2.9/31 successfully created\naddress ip 10.0.2.19/31 successfully created\ninterface connection between QFX5100-183 et-0/0/48 and QFX10K2-178 et-0/0/2 successfully created\ninterface connection between QFX10K2-181 et-0/0/3 and QFX5100-186 et-0/0/49 successfully created\n\n```\n\n## Generate the ansible inventory from Netbox API\n\nThe script  [**ansible_dynamic_inventory.py**](ansible_dynamic_inventory.py) generates the ansible inventory [**hosts**](hosts) from Netbox API  \n\n```\n$ python ansible_dynamic_inventory.py\n```\n```\n$ more hosts \n#Ansible dynamic inventory file generated from Netbox API\n\n[juniper:children]\nqfx10002-36q\nqfx5100-48s-6q\n\n[qfx10002-36q]\nQFX10K2-174 junos_host=172.25.90.174\nQFX10K2-175 junos_host=172.25.90.175\nQFX10K2-178 junos_host=172.25.90.178\nQFX10K2-180 junos_host=172.25.90.180\nQFX10K2-181 junos_host=172.25.90.181\n\n[qfx5100-48s-6q]\nQFX5100-183 junos_host=172.25.90.183\nQFX5100-186 junos_host=172.25.90.186\n\n[dc1]\n[QFX10K2-178]\n[QFX10K2-180]\n[QFX10K2-181]\n[QFX5100-183]\n[QFX5100-186]\n\n[dc2]\n[QFX10K2-174]\n[QFX10K2-175]\n\n[leaf_switch]\n[QFX5100-183]\n[QFX5100-186]\n\n[spine_switch]\n[QFX10K2-174]\n[QFX10K2-175]\n[QFX10K2-178]\n[QFX10K2-180]\n[QFX10K2-181]\n```\n\nThe playbook [**pb_print_junos_facts.yml**](pb_print_junos_facts.yml) has been tested with ansible 2.4.2.0.  \nIt uses the ansible inventory file generated from Netbox API. \n\nRun these commands on Ubuntu 16.04 to install Ansible and its requirements for Junos:\n```\nsudo -s\napt-get update\napt-get install -y python-dev libxml2-dev python-pip libxslt1-dev build-essential libssl-dev libffi-dev git\npip install junos-eznc jxmlease wget ansible==2.4.2.0 requests ipaddress cryptography \n```\n\n```\n# ansible-playbook pb_print_junos_facts.yml\n\nPLAY [Get Facts] ********************************************************************************************************************************************************\n\nTASK [Retrieve information from devices running Junos] ******************************************************************************************************************\nok: [QFX10K2-178]\nok: [QFX10K2-180]\nok: [QFX10K2-174]\nok: [QFX10K2-175]\nok: [QFX10K2-181]\nok: [QFX5100-183]\nok: [QFX5100-186]\n\nTASK [Print some facts] *************************************************************************************************************************************************\nok: [QFX10K2-174] =\u003e {\n    \"msg\": \"device QFX10K2-174 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-175] =\u003e {\n    \"msg\": \"device QFX10K2-175 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-178] =\u003e {\n    \"msg\": \"device QFX10K2-178 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-180] =\u003e {\n    \"msg\": \"device QFX10K2-180 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-181] =\u003e {\n    \"msg\": \"device QFX10K2-181 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX5100-183] =\u003e {\n    \"msg\": \"device QFX5100-183 is a qfx5100-48s-6q running junos version 17.4R1-S1.9\"\n}\nok: [QFX5100-186] =\u003e {\n    \"msg\": \"device QFX5100-186 is a qfx5100-48s-6q running junos version 17.4R1-S1.9\"\n}\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX10K2-174                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-175                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-178                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-180                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-181                : ok=2    changed=0    unreachable=0    failed=0   \nQFX5100-183                : ok=2    changed=0    unreachable=0    failed=0   \nQFX5100-186                : ok=2    changed=0    unreachable=0    failed=0   \n```\n```\n# ansible-playbook pb_print_junos_facts.yml --limit QFX10K2-180\n\nPLAY [Get Facts] ********************************************************************************************************************************************************\n\nTASK [Retrieve information from devices running Junos] ******************************************************************************************************************\nok: [QFX10K2-180]\n\nTASK [Print some facts] *************************************************************************************************************************************************\nok: [QFX10K2-180] =\u003e {\n    \"msg\": \"device QFX10K2-180 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX10K2-180                : ok=2    changed=0    unreachable=0    failed=0   \n```\n```\n# ansible-playbook pb_print_junos_facts.yml --limit dc2\n\nPLAY [Get Facts] ********************************************************************************************************************************************************\n\nTASK [Retrieve information from devices running Junos] ******************************************************************************************************************\nok: [QFX10K2-174]\nok: [QFX10K2-175]\n\nTASK [Print some facts] *************************************************************************************************************************************************\nok: [QFX10K2-174] =\u003e {\n    \"msg\": \"device QFX10K2-174 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-175] =\u003e {\n    \"msg\": \"device QFX10K2-175 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX10K2-174                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-175                : ok=2    changed=0    unreachable=0    failed=0   \n```\n```\n# ansible-playbook pb_print_junos_facts.yml --limit spine_switch\n\nPLAY [Get Facts] ********************************************************************************************************************************************************\n\nTASK [Retrieve information from devices running Junos] ******************************************************************************************************************\nok: [QFX10K2-180]\nok: [QFX10K2-175]\nok: [QFX10K2-174]\nok: [QFX10K2-178]\nok: [QFX10K2-181]\n\nTASK [Print some facts] *************************************************************************************************************************************************\nok: [QFX10K2-174] =\u003e {\n    \"msg\": \"device QFX10K2-174 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-175] =\u003e {\n    \"msg\": \"device QFX10K2-175 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-178] =\u003e {\n    \"msg\": \"device QFX10K2-178 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-180] =\u003e {\n    \"msg\": \"device QFX10K2-180 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\nok: [QFX10K2-181] =\u003e {\n    \"msg\": \"device QFX10K2-181 is a qfx10002-36q running junos version 17.4R1-S1.9\"\n}\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX10K2-174                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-175                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-178                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-180                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-181                : ok=2    changed=0    unreachable=0    failed=0   \n\n```\n```\n# ansible-playbook pb_print_junos_facts.yml --limit qfx5100-48s-6q\n\nPLAY [Get Facts] ********************************************************************************************************************************************************\n\nTASK [Retrieve information from devices running Junos] ******************************************************************************************************************\nok: [QFX5100-183]\nok: [QFX5100-186]\n\nTASK [Print some facts] *************************************************************************************************************************************************\nok: [QFX5100-183] =\u003e {\n    \"msg\": \"device QFX5100-183 is a qfx5100-48s-6q running junos version 17.4R1-S1.9\"\n}\nok: [QFX5100-186] =\u003e {\n    \"msg\": \"device QFX5100-186 is a qfx5100-48s-6q running junos version 17.4R1-S1.9\"\n}\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX5100-183                : ok=2    changed=0    unreachable=0    failed=0   \nQFX5100-186                : ok=2    changed=0    unreachable=0    failed=0   \n```\n## Generate yaml files for Jinja templates or ansible playbooks from Netbox API\n\nThe script [**generate_vars_for_jinja_from_netbox.py**](generate_vars_for_jinja_from_netbox.py) generates yaml files for jinja templates and ansible playbooks from Netbox API. \n\n\nThere is no variable available: \n```\n# ls host_vars\nls: cannot access 'host_vars': No such file or directory\n```\n\nGenerate the variables: \n```\n# python generate_vars_for_jinja_from_netbox.py\n```\n```\n# ls host_vars\nQFX10K2-174  QFX10K2-175  QFX10K2-178  QFX10K2-180  QFX10K2-181  QFX5100-183  QFX5100-186\n```\n```\n# more host_vars/QFX10K2-181/vars_from_netbox_api.yml \nvars_from_netbox_api:\n- address: 10.0.2.15/31\n  interface: et-0/0/0\n- address: 10.0.2.25/31\n  interface: et-0/0/1\n- address: 172.25.90.181/32\n  interface: em0\n```\n```\n# more host_vars/QFX10K2-178/vars_from_netbox_api.yml \nvars_from_netbox_api:\n- address: 10.0.2.9/31\n  interface: et-0/0/0\n- address: 10.0.2.19/31\n  interface: et-0/0/1\n- address: 172.25.90.178/32\n  interface: em0\n```\n\n## Use the yaml files generated from the Netbox API \n\nThe playbook [**pb_check_interfaces.yml**](pb_check_interfaces.yml) uses: \n- the ansible inventory we generated from Netbox API\n- the variables we generated from Netbox API \n\n```\n# ansible-playbook pb_check_interfaces.yml\n\nPLAY [check interface states] *******************************************************************************************************************************************\n\nTASK [check if interfaces admin status is up] ***************************************************************************************************************************\nok: [QFX10K2-174] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.174/32'})\nok: [QFX10K2-175] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.175/32'})\nok: [QFX10K2-180] =\u003e (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.13/31'})\nok: [QFX10K2-178] =\u003e (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.9/31'})\nok: [QFX10K2-181] =\u003e (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.15/31'})\nok: [QFX10K2-180] =\u003e (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.23/31'})\nok: [QFX10K2-181] =\u003e (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.25/31'})\nok: [QFX10K2-178] =\u003e (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.19/31'})\nok: [QFX10K2-180] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.180/32'})\nok: [QFX10K2-181] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.181/32'})\nok: [QFX10K2-178] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.178/32'})\n\nTASK [check if interfaces op status is up] ******************************************************************************************************************************\nok: [QFX10K2-174] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.174/32'})\nok: [QFX10K2-175] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.175/32'})\nok: [QFX10K2-178] =\u003e (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.9/31'})\nok: [QFX10K2-181] =\u003e (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.15/31'})\nok: [QFX10K2-180] =\u003e (item={u'interface': u'et-0/0/0', u'address': u'10.0.2.13/31'})\nok: [QFX10K2-178] =\u003e (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.19/31'})\nok: [QFX10K2-180] =\u003e (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.23/31'})\nok: [QFX10K2-181] =\u003e (item={u'interface': u'et-0/0/1', u'address': u'10.0.2.25/31'})\nok: [QFX10K2-178] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.178/32'})\nok: [QFX10K2-180] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.180/32'})\nok: [QFX10K2-181] =\u003e (item={u'interface': u'em0', u'address': u'172.25.90.181/32'})\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX10K2-174                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-175                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-178                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-180                : ok=2    changed=0    unreachable=0    failed=0   \nQFX10K2-181                : ok=2    changed=0    unreachable=0    failed=0   \n```\n\nThe playbook [**pb_render_template.yml**](pb_render_template.yml) renders the template [**template.j2**](template.j2) using the yaml files built from Netbox API. It saves the generated files in the directory [**render**](render).   \n\n```\n# more pb_render_template.yml \n---\n - name: create a directory \n   hosts: localhost\n   gather_facts: no\n   \n   tasks:\n    \n   - name: create the directory render\n     file: \n        path: \"{{playbook_dir}}/render\" \n        state: directory\n\n - name: render junos configuration template using vars from Netbox API\n   hosts: juniper\n   connection: local\n   gather_facts: no\n\n   tasks:\n\n    - name: render junos configuration template using vars from Netbox API\n      template: \n        src: \"{{ playbook_dir }}/template.j2\" \n        dest: \"{{ playbook_dir }}/render/{{ inventory_hostname }}.conf\"\n\n```\n```\n# more template.j2 \ninterfaces {\n{% for item in vars_from_netbox_api %}\n    {{ item.interface }} {\n        unit 0 {\n            family inet {\n                address {{ item.address }};\n            }\n        }\n    }\n{% endfor %}\n}\nprotocols {\n    lldp {\n{% for item in vars_from_netbox_api %}\n        interface \"{{ item.interface }}\";\n{% endfor %}\n    }\n}\n\n```\n```\n# ls render\nls: cannot access 'render': No such file or directory\n```\n```\n# ansible-playbook pb_render_template.yml \n\nPLAY [create a directory] ***********************************************************************************************************************************************\n\nTASK [create the directory render] **************************************************************************************************************************************\nchanged: [localhost]\n\nPLAY [render junos configuration template using vars from Netbox API] ***************************************************************************************************\n\nTASK [render junos configuration template using vars from Netbox API] ***************************************************************************************************\nchanged: [QFX10K2-181]\nchanged: [QFX10K2-174]\nchanged: [QFX10K2-180]\nchanged: [QFX10K2-175]\nchanged: [QFX10K2-178]\nchanged: [QFX5100-183]\nchanged: [QFX5100-186]\n\nPLAY RECAP **************************************************************************************************************************************************************\nQFX10K2-174                : ok=1    changed=1    unreachable=0    failed=0   \nQFX10K2-175                : ok=1    changed=1    unreachable=0    failed=0   \nQFX10K2-178                : ok=1    changed=1    unreachable=0    failed=0   \nQFX10K2-180                : ok=1    changed=1    unreachable=0    failed=0   \nQFX10K2-181                : ok=1    changed=1    unreachable=0    failed=0   \nQFX5100-183                : ok=1    changed=1    unreachable=0    failed=0   \nQFX5100-186                : ok=1    changed=1    unreachable=0    failed=0   \nlocalhost                  : ok=1    changed=1    unreachable=0    failed=0   \n```\n```\n# ls render\nQFX10K2-174.conf  QFX10K2-175.conf  QFX10K2-178.conf  QFX10K2-180.conf  QFX10K2-181.conf  QFX5100-183.conf  QFX5100-186.conf\n```\n```\n# more render/QFX10K2-181.conf \ninterfaces {\n    et-0/0/0 {\n        unit 0 {\n            family inet {\n                address 10.0.2.15/31;\n            }\n        }\n    }\n    et-0/0/1 {\n        unit 0 {\n            family inet {\n                address 10.0.2.25/31;\n            }\n        }\n    }\n    em0 {\n        unit 0 {\n            family inet {\n                address 172.25.90.181/32;\n            }\n        }\n    }\n}\nprotocols {\n    lldp {\n        interface \"et-0/0/0\";\n        interface \"et-0/0/1\";\n        interface \"em0\";\n    }\n}\n```\n## Delete Netbox configuration with automation\nThe script [**delete_netbox_configuration.py**](delete_netbox_configuration.py) delete the Netbox configuration: \n   - all tenants\n   - all sites\n   - all device-roles\n   - all device-types\n   - all platforms\n   - all interface connections\n   - all devices\n   - all prefixes-roles\n   - all prefixes\n   - all ip addresses\n```\n$ python delete_netbox_configuration.py \n```\n\n## Continuous integration with Travis CI\n\nThere is a github webhook with Travis CI\nThe syntax of the python scripts and ansible playbooks in this repository are tested automatically by Travis CI. \nThe files [**.travis.yml**](.travis.yml) and [**requirements.txt**](requirements.txt) at the root of this repository are used for this.  \n\nHere's the last build status\n[![Build Status](https://travis-ci.org/ksator/netbox_automation.svg?branch=master)](https://travis-ci.org/ksator/netbox_automation)\n\n\n## Looking for more automation solutions\n\nhttps://github.com/ksator?tab=repositories  \nhttps://gitlab.com/users/ksator/projects  \nhttps://gist.github.com/ksator/  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksator%2Fnetbox_automation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksator%2Fnetbox_automation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksator%2Fnetbox_automation/lists"}