├── .gitignore ├── README.md ├── Vagrantfile ├── bootstrap.sh └── config_files ├── gunicorn_config.example.py ├── nginx-netbox.example └── supervisord-netbox.example.conf /.gitignore: -------------------------------------------------------------------------------- 1 | ### Vagrant ### 2 | **/.vagrant 3 | 4 | ### Log Files ### 5 | *.log* 6 | 7 | ### MISC ### 8 | *.DS_Store 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # netbox-vagrant 2 | 3 | **Nuthshell:** Quickest NetBox install for Demo or Production(*recommended that you tweak slightly for production*). 4 | 5 | This repository houses the components needed to build [NetBox](https://github.com/digitalocean/netbox/) using [Vagrant](https://www.vagrantup.com/intro) and [VirtualBox](https://www.virtualbox.org). It is a work in progress; please submit a bug report for any issues you encounter. 6 | 7 | [Vagrant Getting Started](https://www.vagrantup.com/intro/getting-started/index.html) - Quick setup requires installing VirtualBox and Vagrant (selected your supported OS in the links below). 8 | 9 | * [VirtualBox](https://www.virtualbox.org/wiki/Downloads) - You can replace with other virtual platforms. See Vagrant Getting Started above. 10 | * [Vagrant](https://www.vagrantup.com/downloads.html) 11 | 12 | ## Quickstart 13 | 14 | To get NetBox up and running: 15 | 16 | 1. Install Virtual Platform & Vagrant (if not installed already) 17 | 2. Clone [netbox-vagrant git repo](https://github.com/ryanmerolle/netbox-vagrant/) ```# git clone https://github.com/ryanmerolle/netbox-vagrant/ .``` or just download both [Vagrantfile](Vagrantfile) & [bootstrap.sh](bootstrap.sh) and place in the directory you want to launch vagrant from. 18 | 3. Navigate to local repo directory & start vagrant 19 | ```# vagrant up``` 20 | 4. Log into VM (optional) 21 | ```# vagrant ssh``` 22 | 5. Play with Netbox demo in browser of choice [http://netbox.localhost:8080](http://netbox.localhost:8080) (Admin credentials use "admin" for userid and password - can be changed & credentials do not have quotes) 23 | 6. (Optional) [NAPALM Config](http://netbox.readthedocs.io/en/stable/configuration/optional-settings/#napalm_username), [Email Config](http://netbox.readthedocs.io/en/stable/configuration/optional-settings/#email), [LDAP](http://netbox.readthedocs.io/en/stable/installation/ldap/) 24 | 25 | ## Upgrading 26 | The [normal NetBox upgrade process](https://github.com/digitalocean/netbox/blob/develop/docs/installation/upgrading.md) can be followed using the instructions to Clone the Git Repository (latest master release). 27 | 28 | ## Netbox Configuration Used 29 | The [NetBox installation](https://github.com/digitalocean/netbox/blob/develop/docs/installation/netbox.md) process is followed leveraging: 30 | 31 | * VM Memory: 2048 (edit Vagrantfile if you would like to change) 32 | * VM CPUs: 1 (edit Vagrantfile if you would like to change) 33 | * Ubuntu Xenial64 (updated) 34 | * Python 3 (deprecated python2) 35 | * GIT - Cloning the Netbox latest master release from github (as opposed to downloading a tar of a particular release) 36 | * Ngnix (deprecated Apache) 37 | 38 | ## Security 39 | * Netbox/Django superuser account is ```admin``` with a password ```admin``` and an email of ```admin@example.com``` (can be changed after startup) 40 | * SECRET_KEY is randomly generated using generate_secret_key.py 41 | * Postgres DB is setup using account is "nebox" with a password "J5brHrAXFLQSif0K" and the database "netbox" using the default port (all without quotes and can be changed after startup) 42 | * [Forwarded Ports](https://www.vagrantup.com/docs/networking/forwarded_ports.html) - to add additional VM access / port forwarding (ssh, remote psql, etc) 43 | * [Vagrant Credentials](https://www.vagrantup.com/docs/boxes/base.html#default-user-settings) - to understand credentials used for vagrant / Ubuntu VM 44 | 45 | ## Notes 46 | * [bootstrap.sh](bootstrap.sh) can be used to bootstrap any Ubuntu Xenial setup & not just Vagrant (with slight tweaking) 47 | * Additional Support Resources include: 48 | * [NetBox Github page](https://github.com/digitalocean/netbox/) 49 | * [NetBox Read the Docs](http://netbox.readthedocs.io/en/stable/) 50 | * [NetBox-discuss mailing list](https://groups.google.com/forum/#!forum/netbox-discuss) 51 | * [NAPALM Github page](https://github.com/napalm-automation/napalm/) 52 | * [NAPALM Read the Docs](https://napalm.readthedocs.io/) 53 | * [Join the Network to Code community on Slack](https://networktocode.herokuapp.com) - Once setup join the **#netbox** room for help. I'm **ryanmerolle** & usually in this slack room. 54 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | config.vm.box = "ubuntu/xenial64" 6 | config.vm.hostname = "netbox-demo" 7 | 8 | config.vm.network :forwarded_port, guest: 80, host: 8080, id: 'http' 9 | 10 | config.vm.synced_folder "./config_files", "/vagrant" 11 | 12 | #Update VM resources below as needed 13 | config.vm.provider :virtualbox do |vb| 14 | vb.name = "Netbox-Demo" 15 | vb.memory = 2048 16 | vb.cpus = 1 17 | vb.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"] 18 | end 19 | 20 | config.vm.provision :shell, path: "bootstrap.sh" 21 | 22 | end 23 | -------------------------------------------------------------------------------- /bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Prevent 4 | export DEBIAN_FRONTEND=noninteractive 5 | 6 | # Update Ubuntu 7 | printf "Step 1 of 19: Updating Ubuntu..." 8 | apt-get update -y > /dev/null 9 | 10 | # Install Postgres & start service 11 | printf "Step 2 of 19: Installing & starting Postgres..." 12 | apt-get install postgresql libpq-dev -y > /dev/null 13 | sudo service postgresql start 14 | 15 | # Setup Postgres with netbox user, database, and permissions 16 | printf "Step 3 of 19: Setup Postgres with netbox user, database, & permissions." 17 | sudo -u postgres psql -c "CREATE DATABASE netbox" 18 | sudo -u postgres psql -c "CREATE USER netbox WITH PASSWORD 'J5brHrAXFLQSif0K'" 19 | sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE netbox TO netbox" 20 | 21 | # Install nginx 22 | printf "Step 4 of 19: Installing nginx..." 23 | apt-get install nginx -y > /dev/null 24 | 25 | # Install Python 2 26 | printf "Step 5 of 19: Installing Python 3 dependencies..." 27 | apt-get install python3 python3-dev python3-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev redis-server -y > /dev/null 28 | 29 | # Upgrade pip 30 | printf "Step 6 of 19: Upgrading pip\n" 31 | #pip3 install --upgrade pip > /dev/null 32 | pip3 install --upgrade pip==9.0.3 > /dev/null 33 | 34 | # Install gunicorn & supervisor 35 | printf "Step 7 of 19: Installing gunicorn & supervisor..." 36 | pip3 install gunicorn 37 | apt-get install supervisor -y > /dev/null 38 | 39 | printf "Step 8 of 19: Cloning NetBox repo latest stable release..." 40 | # git clone netbox master branch 41 | git clone -b master https://github.com/digitalocean/netbox.git /opt/netbox 42 | 43 | # Install NetBox requirements 44 | printf "Step 9 of 19: Installing NetBox requirements..." 45 | pip3 install -r /opt/netbox/requirements.txt > /dev/null 46 | 47 | # Use configuration.example.py to create configuration.py 48 | printf "Step 10 of 19: Configuring Netbox..." 49 | cp /opt/netbox/netbox/netbox/configuration.example.py /opt/netbox/netbox/netbox/configuration.py 50 | # Update configuration.py with database user, database password, netbox generated SECRET_KEY, & Allowed Hosts 51 | sed -i "s/'USER': '', /'USER': 'netbox', /g" /opt/netbox/netbox/netbox/configuration.py 52 | sed -i "s/'PASSWORD': '', /'PASSWORD': 'J5brHrAXFLQSif0K', /g" /opt/netbox/netbox/netbox/configuration.py 53 | sed -i "s/ALLOWED_HOSTS \= \[\]/ALLOWED_HOSTS \= \['netbox.internal.local', 'netbox.localhost', 'localhost', '127.0.0.1'\]/g" /opt/netbox/netbox/netbox/configuration.py 54 | SECRET_KEY=$( python3 /opt/netbox/netbox/generate_secret_key.py ) 55 | sed -i "s~SECRET_KEY = ''~SECRET_KEY = '$SECRET_KEY'~g" /opt/netbox/netbox/netbox/configuration.py 56 | # Clear SECRET_KEY variable 57 | unset SECRET_KEY 58 | 59 | # Setup apache, gunicorn, & supervisord config using premade examples (need to change netbox-setup) 60 | printf "Step 11 of 19: Configuring nginx..." 61 | cp /vagrant/nginx-netbox.example /etc/nginx/sites-available/netbox 62 | printf "Step 12 of 19: Configuring gunicorn..." 63 | cp /vagrant/gunicorn_config.example.py /opt/netbox/gunicorn_config.py 64 | printf "Step 13 of 19: Configuring supervisor..." 65 | cp /vagrant/supervisord-netbox.example.conf /etc/supervisor/conf.d/netbox.conf 66 | 67 | # Apache Setup (enable the proxy and proxy_http modules, and reload Apache) 68 | printf "Step 14 of 19: Completing web service setup..." 69 | cd /etc/nginx/sites-enabled/ 70 | rm default 71 | ln -s /etc/nginx/sites-available/netbox 72 | service nginx restart 73 | service supervisor restart 74 | 75 | # Install the database schema 76 | printf "Step 15 of 19: Install the database schema..." 77 | python3 /opt/netbox/netbox/manage.py migrate > /dev/null 78 | 79 | # Create admin / admin superuser 80 | printf "Step 16 of 19: Create NetBox superuser..." 81 | echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | python3 /opt/netbox/netbox/manage.py shell > /dev/null 82 | 83 | # Collect Static Files 84 | printf "Step 17 of 19: collectstatic" 85 | python3 /opt/netbox/netbox/manage.py collectstatic --no-input << /dev/null 86 | 87 | # Load Initial Data (Optional) Comment out if you like 88 | printf "Step 18 of 19: Load intial data." 89 | python3 /opt/netbox/netbox/manage.py loaddata initial_data > /dev/null 90 | 91 | # Install NAPALM Drivers 92 | printf "Step 19 of 19: Installing NAPALM Drivers" 93 | pip3 install napalm 94 | 95 | # Fix permissions to folder 96 | chown -R www-data /opt/netbox/netbox/media/image-attachments/ 97 | 98 | # Status Complete 99 | printf "%s\nCOMPLETE: NetBox-Demo Provisioning COMPLETE!!" 100 | printf "%s\nTo login to the Vagrant VM use vagrant ssh in the current directory" 101 | printf "%s\nSee NAPALM and Netbox documentation to get NAPALM working with Netbox and your environment" 102 | printf "%s\nTo login to the Netbox-Demo web portal go to http://netbox.localhost:8080" 103 | printf "%s\nWeb portal superuser credentials are admin / admin" 104 | -------------------------------------------------------------------------------- /config_files/gunicorn_config.example.py: -------------------------------------------------------------------------------- 1 | command = '/usr/bin/gunicorn' 2 | pythonpath = '/opt/netbox/netbox' 3 | bind = '127.0.0.1:8001' 4 | workers = 3 5 | user = 'www-data' -------------------------------------------------------------------------------- /config_files/nginx-netbox.example: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | server_name netbox.localhost 5 | 6 | client_max_body_size 25m; 7 | 8 | location /static/ { 9 | alias /opt/netbox/netbox/static/; 10 | } 11 | 12 | location / { 13 | proxy_pass http://127.0.0.1:8001; 14 | proxy_set_header X-Forwarded-Host $server_name; 15 | proxy_set_header X-Real-IP $remote_addr; 16 | proxy_set_header X-Forwarded-Proto $scheme; 17 | add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; 18 | } 19 | } -------------------------------------------------------------------------------- /config_files/supervisord-netbox.example.conf: -------------------------------------------------------------------------------- 1 | [program:netbox] 2 | command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi 3 | directory = /opt/netbox/netbox/ 4 | user = www-data --------------------------------------------------------------------------------