Puppet Class: netbox::install

Defined in:
manifests/install.pp

Summary

Installs Netbox

Overview

Installs Netbox

Examples:

include netbox::install

Parameters:

  • install_root (Stdlib::Absolutepath)

    The directory where the netbox installation is unpacked

  • version (String)

    The version of Netbox. This must match the version in the tarball. This is used for managing files, directories and paths in the service.

  • download_url (String)

    Where to download the binary installation tarball from.

  • download_checksum (String)

    The expected checksum of the downloaded tarball. This is used for verifying the integrity of the downloaded tarball.

  • download_checksum_type (String)

    The checksum type of the downloaded tarball. This is used for verifying the integrity of the downloaded tarball.

  • download_tmp_dir (Stdlib::Absolutepath)

    Temporary directory for downloading the tarball.

  • user (String)

    The user owning the Netbox installation files, and running the service.

  • group (String)

    The group owning the Netbox installation files, and running the service.

  • install_method (Enum['tarball', 'git_clone']) (defaults to: 'tarball')

    Method for getting the Netbox software

  • include_napalm (Boolean)

    NAPALM allows NetBox to fetch live data from devices and return it to a requester via its REST API. Installation of NAPALM is optional. To enable it, set $include_napalm to true

  • include_django_storages (Boolean)

    By default, NetBox will use the local filesystem to storage uploaded files. To use a remote filesystem, install the django-storages library and configure your desired backend in configuration.py.

  • include_ldap (Boolean)

    Makes sure the packages and the python modules needed for LDAP-authentication are installed and loaded. The LDAP-config itself is not handled by this Puppet module at present. Use the documentation found here: netbox.readthedocs.io/en/stable/installation/5-ldap/ for information about the config file.

  • install_dependencies_from_filesystem (Boolean)

    Used if your machine can’t reach the place pip would normally go to fetch dependencies as it would when running “pip install -r requirements.txt”. Then you would have to fetch those dependencies beforehand and put them somewhere your machine can reach. This can be done by running (on a machine that can reach pip’s normal sources) the following: pip download -r <requirements.txt> -d <destination> Remember to do this on local_requirements.txt also if you have one.

  • python_dependency_path (Stdlib::Absolutepath)

    Path to where pip can find packages when the variable $install_dependencies_from_filesystem is true



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'manifests/install.pp', line 65

class netbox::install (
  Stdlib::Absolutepath $install_root,
  String $version,
  String $download_url,
  String $download_checksum,
  String $download_checksum_type,
  Stdlib::Absolutepath $download_tmp_dir,
  String $user,
  String $group,
  Boolean $include_napalm,
  Boolean $include_django_storages,
  Boolean $include_ldap,
  Boolean $install_dependencies_from_filesystem,
  Stdlib::Absolutepath $python_dependency_path,
  Enum['tarball', 'git_clone'] $install_method = 'tarball',
) {

  $packages =[
    gcc,
    python36,
    python36-devel,
    libxml2-devel,
    libxslt-devel,
    libffi-devel,
    openssl-devel,
    redhat-rpm-config
  ]

  $local_tarball = "${download_tmp_dir}/netbox-${version}.tar.gz"
  $software_directory_with_version = "${install_root}/netbox-${version}"
  $software_directory = "${install_root}/netbox"
  $venv_dir = "${software_directory}/venv"

  $ldap_packages = [openldap-devel]

  ensure_packages($packages)

  if $include_ldap {
    ensure_packages($ldap_packages)
  }

  user { $user:
    system => true,
    gid    => $group,
    home   => $software_directory,
  }

  group { $group:
    system => true,
  }

  if $install_dependencies_from_filesystem {
    $install_requirements_command       = "${venv_dir}/bin/pip3 install -r requirements.txt --no-index --find-links ${python_dependency_path}"
    $install_local_requirements_command = "${venv_dir}/bin/pip3 install -r local_requirements.txt --no-index --find-links ${python_dependency_path}"
  } else {
    $install_requirements_command       = "${venv_dir}/bin/pip3 install -r requirements.txt"
    $install_local_requirements_command = "${venv_dir}/bin/pip3 install -r local_requirements.txt"
  }

  archive { $local_tarball:
      source        => $download_url,
      checksum      => $download_checksum,
      checksum_type => $download_checksum_type,
      extract       => true,
      extract_path  => $install_root,
      creates       => $software_directory_with_version,
      cleanup       => true,
      notify        => Exec['install python requirements'],
    }

    exec { 'netbox permission':
      command     => "chown -R ${user}:${group} ${software_directory_with_version}",
      path        => ['/usr/bin'],
      subscribe   => Archive[$local_tarball],
      refreshonly => true,
    }

  file { $software_directory:
    ensure => 'link',
    target => $software_directory_with_version,
  }
  file { 'local_requirements':
    ensure => 'present',
    path   => "${software_directory}/local_requirements.txt",
    owner  => $user,
    group  => $group,
  }

  if $include_napalm {
    file_line { 'napalm':
      path    => "${software_directory}/local_requirements.txt",
      line    => 'napalm',
      notify  => Exec['install local python requirements'],
      require => File['local_requirements']
    }
  }

  if $include_django_storages {
    file_line { 'django_storages':
      path    => "${software_directory}/local_requirements.txt",
      line    => 'django-storages',
      notify  => Exec['install local python requirements'],
      require => File['local_requirements']
    }
  }

  if $include_ldap {
    file_line { 'ldap':
      path    => "${software_directory}/local_requirements.txt",
      line    => 'django-auth-ldap',
      notify  => Exec['install local python requirements'],
      require => File['local_requirements']
    }
  }

  exec { "python_venv_${venv_dir}":
    command => "/usr/bin/python3 -m venv ${venv_dir}",
    user    => $user,
    creates => "${venv_dir}/bin/activate",
    cwd     => '/tmp',
    unless  => "/usr/bin/grep '^[\\t ]*VIRTUAL_ENV=[\\\\'\\\"]*${venv_dir}[\\\"\\\\'][\\t ]*$' ${venv_dir}/bin/activate",
  }
  ~>exec { 'install python requirements':
    cwd         => $software_directory,
    path        => [ "${venv_dir}/bin", '/usr/bin', '/usr/sbin' ],
    environment => ["VIRTUAL_ENV=${venv_dir}"],
    provider    => shell,
    user        => $user,
    command     => $install_requirements_command,
    onlyif      => "/usr/bin/grep '^[\\t ]*VIRTUAL_ENV=[\\\\'\\\"]*${venv_dir}[\\\"\\\\'][\\t ]*$' ${venv_dir}/bin/activate",
    refreshonly => true,
  }
  ~>exec { 'install local python requirements':
    cwd         => $software_directory,
    path        => [ "${venv_dir}/bin", '/usr/bin', '/usr/sbin' ],
    environment => ["VIRTUAL_ENV=${venv_dir}"],
    provider    => shell,
    user        => $user,
    command     => $install_local_requirements_command,
    onlyif      => "/usr/bin/grep '^[\\t ]*VIRTUAL_ENV=[\\\\'\\\"]*${venv_dir}[\\\"\\\\'][\\t ]*$' ${venv_dir}/bin/activate",
    refreshonly => true,
  }
}