How to install Netbox
NetBox is an open source web application the is design to manage a network infrastructure.
In this tutorial, we will be installing Netbox using puppet for the installation and a bash script for the basic configuration.
Prerequisites
For this turtorail, we will need:
- A puppet master node (puppet version 4.10)
- The netbox node (Debian 9 Stretch and puppet client vesion 4.8)
- The puppetlabs postgresql module
- The puppetlabs-vcsrepo module
Installation
We will not convert the installation and configuration of puppet master in this tutorial. if you do not have a puppet master server in your environment, you can do all the steps below manually by following the instructions in the reference section. Once done, you can continue with this tutorial from the configuration section.
Download modules
Login to your puppet master node and issue the command below to download the puppetlabs postgresql module
sudo puppet module install puppetlabs-postgresql --version 5.9.0
This will download the postgresql moudle and save it into
/etc/puppetlabs/code/environments/production/modules$
Next we will download the puppetlabs vcsrepo module using the command below
sudo puppet module install puppetlabs-vcsrepo --version 2.3.0
This will download the vcsrepo moudle and save it into
/etc/puppetlabs/code/environments/production/modules$
Create the class
Let us create our netbox_install class that will be used to install Netbox and Posgresql. Under /etc/puppetlabs/code/environments/production/modules/$ create netbox directory
sudo mkdir /etc/puppetlabs/code/environments/production/modules/netbox/$
Then create the manifests director under the netbox directory
sudo mkdir /etc/puppetlabs/code/environments/production/modules/netbox/manifests$
Navigate to the sudo mkdir /etc/puppetlabs/code/environments/production/modules/netbox/manifests$ and create a file called netbox_install.pp
sudo vi netbox_install.pp
Copy and paste the content below into the file (netbox_install.pp)
#This class will install netbox on Debian 9
class netbox::netbox_install {
#Install needed packages
Package { ensure => "installed"}
package { "libpq-dev":}
package { "python3":}
package { "python3-dev":}
package { "python3-setuptools":}
package { "build-essential":}
package { "libxml2-dev":}
package { "libxslt1-dev":}
package { "libffi-dev":}
package { "graphviz":}
package { "libssl-dev":}
package { "zlib1g-dev":}
package { "python3-pip":}
package { "git":}
package { "redis-server":}
package { "nginx":}
package { "supervisor":}
#Install postgresql to use as database
# Create a hash from Hiera Data with the Databases
$myPostgresDb = hiera('postgresql::server::db', {})
# With Create Resource Converts a hash into a set of resources
create_resources('postgresql::server::db', $myPostgresDb)
# Create the netbox user
user { 'netbox':
ensure => 'present',
comment => 'netbox',
managehome => false,
password => 'netbox_user_password',
}
# Create the netbox directory
file { '/opt/netbox':
ensure => directory,
owner => 'netbox',
group => 'netbox',
mode => '0766',
}
# Download netbox fron github.com
vcsrepo { '/opt/netbox':
ensure => present,
provider => git,
source => 'https://github.com/digitalocean/netbox.git',
user => 'netbox',
}
#
package { 'napalm':
ensure => 'installed',
provider => 'pip3',
}
package { 'django-rq':
ensure => 'installed',
provider => 'pip3',
}
}
Add the node to site.pp
On your puppet master node open the site.pp file and add the netbox node like below
node netbox2001 {
include netbox::netbox_install
include postgresql::server
}
The include postgresql::server will install postgresql on the node with no password.How to setup the password is covert in the hiera section below.
Setup hiera
Under your hieradata directory, create a directory called hosts
/etc/puppetlabs/code/environments/production/hieradata/hosts
Then create a yaml file with the name of the netbox node
vi netbox.yaml
Copy and paste the the content below into the file
--- postgresql::server::postgres_password: postgre_password postgresql::server::db: netbox: user: netbox password: netbox_user_passsword postgresql::server::role: netbox: password_hash: '*EAA615A0970C05B84915C0772FD1C23831586837' postgresql::server::database_grant: netbox: privilege: ALL db: netbox role: netbox
By default after installing Posgretsql there is no password so the first line of the code above will setup a password.In the same code we will create a database called netbox and a user for that database netbox who has full privilege on the database.
Run puppet
Login into your netbox node and run the command
sudo puppet agent -t
If you have no errors, go to the next step to verify that we have Postgresql installed and we can login with the postgrea default user and netbox user with the password created. Verify too that we have the netbox database was create.
Verification
- login with the defaut user postgres
psql -U postgres -W -h localhost
When prompt, enter the password
ppaul@netbox2001:~$ psql -U postgres -W -h localhost Password for user postgres: psql (9.6.10) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. postgres=#
Type \q to exit and test login with the netbox user
- Login with the netbox user
ppaul@netbox2001:~$ psql -U netbox -W -h localhost Password for user netbox: psql (9.6.10) SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off) Type "help" for help. netbox=>
- verify that the netbox database exist
after loging in as the netbox user, at the prompt, type "\l"
netbox=> \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
netbox | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =T/postgres +
| | | | | postgres=CTc/postgres+
| | | | | netbox=CTc/postgres
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
netbox=>