Skip to content

Commit

Permalink
Rework the whole role for NetBox 2.5.
Browse files Browse the repository at this point in the history
Only support Debian 9 for now but the role will be extend later. All
the role has been rewritten. NetBox is now setup using a virtualenv to
avoid messing with the Python dependencies in the system. Also rework
variables to set, mostly to configure NetBox.
  • Loading branch information
gmazoyer committed Dec 13, 2018
1 parent 360c372 commit 7c400dd
Show file tree
Hide file tree
Showing 25 changed files with 366 additions and 425 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### VirtualEnv ###
.Python
[Bb]in
[Ii]nclude
[Ll]ib
[Ll]ib64
[Ll]ocal
[Ss]cripts
[Ss]hare
pyvenv.cfg
.venv
pip-selfcheck.json
6 changes: 0 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ env:
- distro: debian9
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
- distro: ubuntu1804
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"

before_install:
- 'docker pull gmazoyer/ansible-docker-${distro}:latest'
Expand Down
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Setup for the PostgreSQL database:

Where to get NetBox and which version:

netbox_version: v2.3.4
netbox_version: v2.5.1
netbox_git_url: https://github.com/digitalocean/netbox.git

Where to install NetBox:
Expand All @@ -50,40 +50,45 @@ Set the timezone to be used (a list of available TZs can be found

netbox_config_time_zone: UTC

The username and email for the super user. Its password must be set manually
via the manage.py tool of the application:
The username, password and email for the super user.

netbox_superuser_username: admin
netbox_superuser_password: admin
netbox_superuser_email: admin@example.com

Force user to login to see data recorded inside NetBox:

netbox_login_required: false

LDAP can be used as authentication mechanism. It must be enabled, and the whole
LDAP configuration has to be provided in the following variables (see NetBox
[documentation](http://netbox.readthedocs.io/en/latest/installation/ldap/)):

netbox_setup_ldap_auth: false
netbox_ldap_config: ""

NAPALM integration with username and password to be used when connecting to
devices:
NAPALM integration, please note that you must set the username and password for
NAPALM in the configuration otherwise it will not be enabled:

netbox_use_napalm: false
netbox_devices_username: ''
netbox_devices_password: ''

Whether or not to load the initial data of NetBox:

netbox_load_initial_data: true

The configuration for NetBox must be given as `key: value` pairs like the
following, please note that the secret key does not need to be given as it will
be generated automatically:

netbox_config:
ALLOWED_HOSTS:
- localhost
- 127.0.0.1
TIME_ZONE: "Europe/Paris"

Configuration for the backend web servers:

netbox_setup_web_backend: false
netbox_gunicorn_address: 127.0.0.1
netbox_gunicorn_port: 8001
netbox_gunicorn_workers_number: 3
netbox_gunicorn_workers_number: 4
netbox_gunicorn_user: root
netbox_supervisor_user: root

Expand Down
38 changes: 22 additions & 16 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
---
# Database related variables (password must be changed)
netbox_database: netbox
netbox_database_user: netbox
netbox_database_password: netbox
netbox_database_host: localhost

# Git URL and version to use, version must be a Git tag
netbox_version: v2.3.4
netbox_version: v2.5.1
netbox_git_url: https://github.com/digitalocean/netbox.git

# Where to install Netbox
netbox_install_directory: /opt/netbox
netbox_virtualenv_path: "{{ netbox_install_directory }}/venv"

# Configuration settings, to be ajusted, especially the secret key
netbox_config_allowed_hosts:
- localhost
- netbox.example.com
netbox_config_secret_key: R+9A&c7R935e(5pI5t!_8s1(hXGHmUIUm!X+)O-^Js4bII12_t
netbox_config_time_zone: UTC
# Which user/group should own the files
netbox_user: netbox
netbox_group: netbox
netbox_user_home_directory: /home/netbox

# Mostly used for the first setup, superuser password still need to be set
netbox_superuser_username: admin
netbox_superuser_password: admin
netbox_superuser_email: admin@example.com
netbox_load_initial_data: true

Expand All @@ -41,9 +35,21 @@ netbox_ldap_config: ""
netbox_setup_web_backend: false
netbox_gunicorn_address: 127.0.0.1
netbox_gunicorn_port: 8001
netbox_gunicorn_workers_number: 3
netbox_gunicorn_user: root
netbox_supervisor_user: root
netbox_gunicorn_workers_number: 4

# Web frontend variables (not configured by default)
netbox_setup_web_frontend: false

# Database related variables (password must be changed)
netbox_database: netbox
netbox_database_user: netbox
netbox_database_password: netbox
netbox_database_host: localhost

# Configuration
netbox_config:
ALLOWED_HOSTS:
- localhost
- 127.0.0.1
MEDIA_ROOT: "{{ netbox_install_directory }}/netbox/media"
REPORTS_ROOT: "{{ netbox_install_directory }}/netbox/reports"
9 changes: 8 additions & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---
- name: restart netbox
supervisorctl:
name: netbox
state: restarted
when: netbox_setup_web_backend

- name: restart apache2
service:
name: "{{ apache2_service }}"
state: restarted
state: restarted
when: netbox_setup_web_frontend
8 changes: 2 additions & 6 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
---
galaxy_info:
author: Guillaume Mazoyer
description: A role to install and update Netbox.
description: A role to install and update NetBox.
license: GPL-3+
min_ansible_version: 2.1.0
min_ansible_version: 2.5.0
platforms:
- name: Debian
versions:
- stretch
- name: Ubuntu
versions:
- xenial
- bionic
galaxy_tags:
- system
- networking
Expand Down
28 changes: 0 additions & 28 deletions tasks/include-vars.yml

This file was deleted.

33 changes: 33 additions & 0 deletions tasks/include_vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# Include variables and define needed ones
- name: include os-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"

- name: define python packages
set_fact:
netbox_python_packages: "{{ __netbox_python_packages | list }}"
when: netbox_python_packages is not defined

- name: define postgresql packages
set_fact:
netbox_postgresql_packages: "{{ __netbox_postgresql_packages | list }}"
when: netbox_postgresql_packages is not defined

- name: define other packages
set_fact:
netbox_other_packages: "{{ __netbox_other_packages | list }}"
when: netbox_other_packages is not defined

- name: define web backend packages
set_fact:
netbox_web_backend_packages: "{{ __netbox_web_backend_packages | list }}"
when: netbox_web_backend_packages is not defined

- name: define web frontend packages
set_fact:
netbox_web_frontend_packages: "{{ __netbox_web_frontend_packages | list }}"
when: netbox_web_frontend_packages is not defined
33 changes: 0 additions & 33 deletions tasks/install-packages.yml

This file was deleted.

12 changes: 12 additions & 0 deletions tasks/install_packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: install required packages
package:
name: "{{ __netbox_required_packages | flatten}}"
state: present
vars:
__netbox_required_packages:
- "{{ netbox_python_packages }}"
- "{{ netbox_postgresql_packages }}"
- "{{ netbox_other_packages }}"
- "{{ netbox_web_backend_packages if netbox_setup_web_backend else [] }}"
- "{{ netbox_web_frontend_packages if netbox_setup_web_frontend else [] }}"
29 changes: 21 additions & 8 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
---
- include: include-vars.yml
- import_tasks: include_vars.yml
- import_tasks: install_packages.yml

- include: install-packages.yml
- name: ensure python 3 is used
set_fact:
ansible_python_interpreter: "{{ netbox_python_binary }}"

- include: setup-database.yml
- block:
- name: create netbox group
group:
name: "{{ netbox_group }}"

- include: setup-netbox.yml
- name: create netbox user
user:
name: "{{ netbox_user }}"
group: "{{ netbox_group }}"
home: "{{ netbox_user_home_directory }}"

- include: setup-web-backend.yml
when: netbox_setup_web_backend
- import_tasks: setup_database.yml
when: netbox_database_host == 'localhost'
- import_tasks: setup_netbox.yml

- include: setup-web-frontend.yml
when: netbox_setup_web_frontend
- include: setup_web_backend.yml
when: netbox_setup_web_backend
- include: setup_web_frontend.yml
when: netbox_setup_web_frontend

0 comments on commit 7c400dd

Please sign in to comment.