Skip to content

Commit 772f6c4

Browse files
OldsOlds
authored andcommitted
initial commit
1 parent 4352c16 commit 772f6c4

File tree

9 files changed

+233
-0
lines changed

9 files changed

+233
-0
lines changed

local.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ansible-playbook -i localhost, -c local main.yml
2+
3+
sudo /opt/netbox/netbox/manage.py createsuperuser
4+
sudo /opt/netbox/netbox/manage.py collectstatic
5+

main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
3+
- hosts: all
4+
user: deploy
5+
become: True
6+
gather_facts: True
7+
vars_files:
8+
- vars/vars.yml
9+
10+
roles:
11+
- netbox
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
command = '/usr/bin/gunicorn'
2+
pythonpath = '/opt/netbox/netbox'
3+
bind = '127.0.0.1:8001'
4+
workers = 3
5+
user = 'www-data'

roles/netbox/files/netbox.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[program:netbox]
2+
command = gunicorn -c /opt/netbox/gunicorn_config.py netbox.wsgi
3+
directory = /opt/netbox/netbox/
4+
user = www-data

roles/netbox/handlers/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- name: restart nginx
2+
service: name=nginx state=restarted
3+
- name: restart supervisor
4+
service: name=supervisor state=restarted

roles/netbox/tasks/main.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
- name: Install netbox dependencies
2+
apt: pkg={{ item }} state=present
3+
with_items:
4+
- postgresql
5+
- libpq-dev
6+
- python-psycopg2
7+
- git
8+
- python-pip
9+
- python-dev
10+
- libxml2-dev
11+
- libxslt1-dev
12+
- libffi-dev
13+
- graphviz
14+
- nginx
15+
- gunicorn
16+
- supervisor
17+
18+
19+
- name: Clone netbox git repository
20+
git: repo=https://github.com/digitalocean/netbox.git
21+
dest=/opt/netbox
22+
version=master
23+
24+
- name: Upgrade pip
25+
pip: name=pip state=latest
26+
27+
- name: Install pip dependencies
28+
pip: requirements=/opt/netbox/requirements.txt
29+
30+
- name: Set postgres password
31+
command: >
32+
sudo -u {{ db_admin_username }} psql -d {{ db_admin_username }}
33+
-c "ALTER USER postgres with password '{{ db_admin_password }}';"
34+
35+
- name: Create database user for netbox
36+
postgresql_user: >
37+
login_host=localhost login_user={{ db_admin_username }}
38+
login_password="{{ db_admin_password }}" name="{{ netbox_db_username }}"
39+
password="{{ netbox_db_password }}" state=present
40+
41+
- name: Create database for netbox
42+
postgresql_db: >
43+
login_host=localhost login_user={{ db_admin_username }}
44+
login_password="{{ db_admin_password }}" name={{ netbox_db_database }}
45+
state=present owner={{ netbox_db_username }}
46+
47+
- name: Configure netbox
48+
template:
49+
src=roles/netbox/templates/configuration.py.j2
50+
dest=/opt/netbox/netbox/netbox/configuration.py
51+
52+
- name: Run migrations
53+
command: /opt/netbox/netbox/manage.py migrate
54+
55+
- name: Configure gunicorn
56+
copy:
57+
src=roles/netbox/files/gunicorn_config.py
58+
dest=/opt/netbox/gunicorn_config.py
59+
notify: restart supervisor
60+
61+
- name: Configure supervisord
62+
copy:
63+
src=roles/netbox/files/netbox.conf
64+
dest=/etc/supervisor/conf.d/netbox.conf
65+
notify: restart supervisor
66+
67+
- name: Configure nginx
68+
template:
69+
src=roles/netbox/templates/netbox.j2
70+
dest=/etc/nginx/sites-available/netbox
71+
notify: restart nginx
72+
73+
- name: Remove nginx default configuration
74+
file: path=/etc/nginx/sites-enabled/default state=absent
75+
notify: restart nginx
76+
77+
- name: Enable netbox site in nginx
78+
file:
79+
src=/etc/nginx/sites-available/netbox
80+
dest=/etc/nginx/sites-enabled/netbox
81+
state=link
82+
notify: restart nginx
83+
84+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# {{ ansible_managed }}
2+
3+
#########################
4+
# #
5+
# Required settings #
6+
# #
7+
#########################
8+
9+
# This is a list of valid fully-qualified domain names (FQDNs) for the NetBox server. NetBox will not permit write
10+
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
11+
#
12+
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
13+
ALLOWED_HOSTS = ['{{ netbox_fqdn }}']
14+
15+
# PostgreSQL database configuration.
16+
DATABASE = {
17+
'NAME': 'netbox', # Database name
18+
'USER': '{{ netbox_db_username }}', # PostgreSQL username
19+
'PASSWORD': '{{ netbox_db_password }}', # PostgreSQL password
20+
'HOST': '{{ netbox_db_host }}', # Database server
21+
'PORT': '{{ netbox_db_port }}', # Database port (leave blank for default)
22+
}
23+
24+
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
25+
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
26+
# symbols. NetBox will not run without this defined. For more information, see
27+
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
28+
SECRET_KEY = '{{ netbox_secret_key }}'
29+
30+
31+
#########################
32+
# #
33+
# Optional settings #
34+
# #
35+
#########################
36+
37+
# Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
38+
# application errors (assuming correct email settings are provided).
39+
ADMINS = [
40+
# ['{{ netbox_admin_name }}', '{{ netbox_admin_email }}'],
41+
]
42+
43+
# Email settings
44+
EMAIL = {
45+
'SERVER': 'localhost',
46+
'PORT': 25,
47+
'USERNAME': '',
48+
'PASSWORD': '',
49+
'TIMEOUT': 10, # seconds
50+
'FROM_EMAIL': '',
51+
}
52+
53+
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
54+
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
55+
LOGIN_REQUIRED = False
56+
57+
# Setting this to True will display a "maintenance mode" banner at the top of every page.
58+
MAINTENANCE_MODE = False
59+
60+
# Credentials that NetBox will use to access live devices.
61+
NETBOX_USERNAME = '{{ netbox_user }}'
62+
NETBOX_PASSWORD = '{{ netbox_password }}'
63+
64+
# Determine how many objects to display per page within a list. (Default: 50)
65+
PAGINATE_COUNT = 50
66+
67+
# Time zone (default: UTC)
68+
TIME_ZONE = 'UTC'
69+
70+
# Date/time formatting. See the following link for supported formats:
71+
# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
72+
DATE_FORMAT = 'N j, Y'
73+
SHORT_DATE_FORMAT = 'Y-m-d'
74+
TIME_FORMAT = 'g:i a'
75+
SHORT_TIME_FORMAT = 'H:i:s'
76+
DATETIME_FORMAT = 'N j, Y g:i a'
77+
SHORT_DATETIME_FORMAT = 'Y-m-d H:i'

roles/netbox/templates/netbox.j2

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# {{ ansible_managed }}
2+
server {
3+
listen 80;
4+
5+
server_name {{ netbox_fqdn }};
6+
7+
access_log off;
8+
9+
location /static/ {
10+
alias /opt/netbox/netbox/static/;
11+
}
12+
13+
location / {
14+
proxy_pass http://127.0.0.1:8001;
15+
proxy_set_header X-Forwarded-Host $server_name;
16+
proxy_set_header X-Real-IP $remote_addr;
17+
proxy_set_header X-Forwarded-Proto $scheme;
18+
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
19+
}
20+
}

vars/vars.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
db_admin_username: postgres
3+
db_admin_password: "@#$%agfHWRSAvytrqew87yt"
4+
netbox_db_username: netbox
5+
netbox_db_password: "FDJHsdb%^346eDSGF"
6+
netbox_db_database: netbox
7+
netbox_db_host: localhost
8+
# leave blank for default port
9+
netbox_db_port:
10+
11+
# Allowed Host
12+
netbox_fqdn: localhost
13+
14+
# Use the script located at netbox-playbook/generate_secret_key.py to generate a suitable key.
15+
netbox_secret_key: "zOpdppS%P0XWXCdrMK-Fn_%dl_naCOo+@FS&aou&w#We*B0drZ"
16+
17+
# Admin user
18+
netbox_admin_name: "James Olds"
19+
netbox_admin_email: "[email protected]"
20+
21+
# Network device login
22+
netbox_user:
23+
netbox_password:

0 commit comments

Comments
 (0)