Difference between revisions of "How to install Netbox"

From ppwiki
Jump to navigation Jump to search
Line 95: Line 95:
  
 
==Setup hiera==
 
==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::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
 +
 
==Run puppet==
 
==Run puppet==
  

Revision as of 01:37, 10 September 2018

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 => 'enigmT@2018',
       }
# 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

}

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::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

Run puppet

Configuration

Conclusion

References

https://netbox.readthedocs.io/en/stable/