Initial work on netbox role
Change-Id: I8e51dc7d5f21d3c83b3d8ab3955467c6069c7c74
diff --git a/.cookiecutter_params.json b/.cookiecutter_params.json
new file mode 100644
index 0000000..282632e
--- /dev/null
+++ b/.cookiecutter_params.json
@@ -0,0 +1,24 @@
+{
+ "_template": "../cookiecutters/role/",
+ "author": "Open Networking Foundation",
+ "company": "Open Networking Foundation",
+ "description": "NetBox IPAM System",
+ "email": "support@opennetworking.org",
+ "issue_tracker_url": "https://jira.opennetworking.org/",
+ "license": "Apache-2.0",
+ "min_ansible_version": "2.9.5",
+ "molecule_privileged": "true",
+ "platform": "deleteme",
+ "platforms": {
+ "Ubuntu": [
+ "16.04",
+ "18.04"
+ ]
+ },
+ "role_defaults": {
+ "example_default1": "example_value1",
+ "example_default2": "example_value2"
+ },
+ "role_name": "netbox",
+ "year": "2020"
+}
diff --git a/.gitreview b/.gitreview
new file mode 100644
index 0000000..555c178
--- /dev/null
+++ b/.gitreview
@@ -0,0 +1,5 @@
+[gerrit]
+host=gerrit.opencord.org
+port=29418
+project=ansible/role/netbox.git
+defaultremote=origin
diff --git a/.reuse/dep5 b/.reuse/dep5
new file mode 100644
index 0000000..36ce305
--- /dev/null
+++ b/.reuse/dep5
@@ -0,0 +1,5 @@
+Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
+
+Files: .cookiecutter_params.json VERSION .gitreview
+Copyright: 2020 Open Networking Foundation
+License: Apache-2.0
diff --git a/LICENSES/Apache-2.0.txt b/LICENSES/Apache-2.0.txt
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSES/Apache-2.0.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8a5db02
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,39 @@
+# netbox Makefile
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+SHELL = bash -eu -o pipefail
+
+.DEFAULT_GOAL := help
+.PHONY: test lint yamllint ansiblelint license help
+
+test: ## run tests on the playbook with molecule
+ molecule --version
+ molecule test
+
+lint: yamllint ansiblelint ## run all lint checks
+
+# all YAML files
+YAML_FILES ?= $(shell find . -type f \( -name '*.yaml' -o -name '*.yml' \) -print )
+
+yamllint: ## lint check with yamllint
+ yamllint --version
+ yamllint \
+ -d "{extends: default, rules: {line-length: {max: 99}}}" \
+ -s $(YAML_FILES)
+
+ansiblelint: ## lint check with ansible-lint
+ ansible-lint --version
+ ansible-lint -v .
+ ansible-lint -v molecule/*/*
+
+license: ## Check license with the reuse tool
+ reuse --version
+ reuse --root . lint
+
+help: ## Print help for each target
+ @echo netbox test targets
+ @echo
+ @grep '^[[:alnum:]_-]*:.* ##' $(MAKEFILE_LIST) \
+ | sort | awk 'BEGIN {FS=":.* ## "}; {printf "%-25s %s\n", $$1, $$2};'
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4470b42
--- /dev/null
+++ b/README.md
@@ -0,0 +1,57 @@
+<!--
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+--!>
+# netbox
+
+This role installs or updates the [NetBox IPAM/DCIM
+System](https://github.com/netbox-community/netbox).
+
+By default, it installs in `/opt/netbox`, which is a symlink to
+`/opt/netbox-<version>`
+
+Media and other uploaded files are stored in `/opt/netbox_media`
+
+This role runs the `update.sh` script during execution, which handles initial
+database creation, upgrade migration, etc.
+
+## Requirements
+
+Must have PostgreSQL and Redis roles installed.
+
+Likely also want to have the NGINX webserver, configured to proxy to gunicorn,
+and to serve static files directly:
+
+```
+ proxy_pass: "http://localhost:8001"
+ extra_config: |
+ location /static/ {
+ alias /opt/netbox/netbox/static/;
+ }
+```
+
+Minimum ansible version: 2.9.5
+
+## Defaults
+
+See `defaults/main.yml`. Most of these variables are either related to the
+database, the initial superuser on the site, or specific to Netbox, in which
+case you should refer to the [NetBox
+documentation](https://netbox.readthedocs.io/en/stable/).
+
+## Example Playbook
+
+```yaml
+- hosts: netbox
+ roles:
+ - nginx
+ - postgres
+ - redis
+ - netbox
+```
+
+## License and Author
+
+© 2020 Open Networking Foundation <support@opennetworking.org>
+
+License: Apache-2.0
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..c0ab82c
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.1-dev
diff --git a/defaults/main.yml b/defaults/main.yml
new file mode 100644
index 0000000..0b35e19
--- /dev/null
+++ b/defaults/main.yml
@@ -0,0 +1,36 @@
+---
+# netbox defaults/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+netbox_version: "2.9.3"
+netbox_version_checksum: "sha256:c9e47993b265ccdb0b88f27c9b023e8adee003d93d478f85c16183baee5586d4"
+
+# unix username/groupname
+netbox_username: "netbox"
+netbox_groupname: "netbox"
+netbox_comment: "NetBox IPAM and DCIM tool"
+
+netbox_dist_dir: "/opt/dist/netbox"
+netbox_working_dir: "/opt/netbox"
+netbox_media_dir: "/opt/netbox_media"
+
+# configuration within NetBox
+netbox_allowed_hosts:
+ - "127.0.0.1"
+
+# secret key: https://docs.djangoproject.com/en/3.0/ref/settings/#std:setting-SECRET_KEY
+netbox_secret_key: "notasecretkey1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+
+# postgres db settings
+netbox_pg_db: "netbox"
+netbox_pg_db_username: "netboxuser"
+netbox_pg_db_password: "netboxpass"
+
+# Admin (superuser) account
+
+netbox_createsuperuser: true
+netbox_superuser_username: "netboxadmin"
+netbox_superuser_password: "netboxadminpass"
+netbox_superuser_email: "support@opennetworking.org"
diff --git a/handlers/main.yml b/handlers/main.yml
new file mode 100644
index 0000000..0f231c4
--- /dev/null
+++ b/handlers/main.yml
@@ -0,0 +1,22 @@
+---
+# netbox handlers/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: start-netbox
+ service:
+ name: "{{ item }}"
+ state: "started"
+ enabled: true
+ with_items:
+ - "netbox"
+ - "netbox-rq"
+
+- name: restart-netbox
+ service:
+ name: "{{ item }}"
+ state: "restarted"
+ with_items:
+ - "netbox"
+ - "netbox-rq"
diff --git a/meta/main.yml b/meta/main.yml
new file mode 100644
index 0000000..9563eb9
--- /dev/null
+++ b/meta/main.yml
@@ -0,0 +1,27 @@
+---
+# netbox meta/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+galaxy_info:
+ author: Open Networking Foundation
+ description: NetBox IPAM System
+ company: Open Networking Foundation
+
+ issue_tracker_url: https://jira.opennetworking.org/
+
+ license: Apache-2.0
+
+ min_ansible_version: 2.9.5
+
+ platforms:
+ - name: Ubuntu
+ versions:
+ - "16.04"
+ - "18.04"
+
+ galaxy_tags:
+ - netbox
+
+dependencies: []
diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml
new file mode 100644
index 0000000..2b047d1
--- /dev/null
+++ b/molecule/default/converge.yml
@@ -0,0 +1,12 @@
+---
+# netbox molecule/default/verify.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: Converge
+ hosts: all
+ tasks:
+ - name: "Include netbox"
+ include_role:
+ name: "netbox"
diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml
new file mode 100644
index 0000000..d33ec80
--- /dev/null
+++ b/molecule/default/molecule.yml
@@ -0,0 +1,29 @@
+---
+# netbox molecule/default/molecule.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+dependency:
+ name: galaxy
+driver:
+ name: docker
+platforms:
+ - name: "ubuntu-18.04-priv"
+ image: "quay.io/paulfantom/molecule-systemd:ubuntu-18.04"
+ privileged: true
+ volumes:
+ - "/sys/fs/cgroup:/sys/fs/cgroup:ro"
+ - name: "debian-10-priv"
+ image: "quay.io/paulfantom/molecule-systemd:debian-10"
+ privileged: true
+ volumes:
+ - "/sys/fs/cgroup:/sys/fs/cgroup:ro"
+provisioner:
+ name: ansible
+ inventory:
+ host_vars:
+ debian-10-priv:
+ ansible_python_interpreter: /usr/bin/python3
+verifier:
+ name: ansible
diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml
new file mode 100644
index 0000000..7c67f8a
--- /dev/null
+++ b/molecule/default/prepare.yml
@@ -0,0 +1,27 @@
+---
+# netbox molecule/default/prepare.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: Prepare for NetBox by installing dependency roles
+ hosts: all
+
+ vars:
+ pgsql_users:
+ - name: "netboxuser"
+ password: "netboxpass"
+ pgsql_databases:
+ - name: "netbox"
+ owner: "netboxuser"
+
+ pre_tasks:
+ - name: Install GPG to support adding apt repo keys
+ apt:
+ name: "gpg"
+ state: "present"
+ update_cache: true
+
+ roles:
+ - postgresql
+ - redis
diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml
new file mode 100644
index 0000000..e244464
--- /dev/null
+++ b/molecule/default/verify.yml
@@ -0,0 +1,17 @@
+---
+# netbox molecule/default/verify.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: Verify
+ hosts: all
+ tasks:
+
+ - name: Check that NetBox is running
+ uri:
+ url: http://127.0.0.1:8001/
+ status_code: 200
+ return_content: true
+ register: webpage
+ failed_when: "'Home - NetBox' not in webpage.content"
diff --git a/tasks/Debian.yml b/tasks/Debian.yml
new file mode 100644
index 0000000..dc1f461
--- /dev/null
+++ b/tasks/Debian.yml
@@ -0,0 +1,36 @@
+---
+# netbox tasks/Debian.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+# prereqs given here:
+# https://netbox.readthedocs.io/en/stable/installation/3-netbox/#install-system-packages
+- name: Install NetBox Prereqs
+ apt:
+ name:
+ - "python3"
+ - "python3-pip"
+ - "python3-venv"
+ - "python3-dev"
+ - "build-essential"
+ - "libxml2-dev"
+ - "libxslt1-dev"
+ - "libffi-dev"
+ - "libpq-dev"
+ - "libssl-dev"
+ - "zlib1g-dev"
+ state: "present"
+ update_cache: true
+ cache_valid_time: 3600
+
+- name: Create systemd service unit files for NetBox services
+ template:
+ src: "{{ item }}.j2"
+ dest: "/etc/systemd/system/{{ item }}"
+ owner: "root"
+ group: "root"
+ mode: "0644"
+ with_items:
+ - "netbox.service"
+ - "netbox-rq.service"
diff --git a/tasks/main.yml b/tasks/main.yml
new file mode 100644
index 0000000..e4f2ada
--- /dev/null
+++ b/tasks/main.yml
@@ -0,0 +1,109 @@
+---
+# netbox tasks/main.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+- name: include OS-specific vars
+ include_vars: "{{ ansible_os_family }}.yml"
+
+- name: include OS-specific tasks
+ include_tasks: "{{ ansible_os_family }}.yml"
+
+- name: Create group for NetBox
+ group:
+ name: "{{ netbox_groupname }}"
+
+- name: Create user for NetBox
+ user:
+ name: "{{ netbox_username }}"
+ group: "{{ netbox_groupname }}"
+ comment: "{{ netbox_comment }}"
+ shell: "{{ netbox_shell }}"
+ system: true
+ password_lock: true
+
+- name: Create NetBox dist dir
+ file:
+ path: "{{ netbox_dist_dir }}"
+ state: directory
+ owner: "root"
+ group: "root"
+ mode: "0755"
+
+- name: Download NetBox distribution .tgz file
+ get_url:
+ url: "https://github.com/netbox-community/netbox/archive/v{{ netbox_version }}.tar.gz"
+ dest: "{{ netbox_dist_dir }}/netbox_{{ netbox_version }}.tar.gz"
+ owner: "root"
+ group: "root"
+ mode: "0644"
+ checksum: "{{ netbox_version_checksum }}"
+
+- name: Unarchive NetBox distribution
+ unarchive:
+ remote_src: true
+ src: "{{ netbox_dist_dir }}/netbox_{{ netbox_version }}.tar.gz"
+ dest: "/opt"
+ owner: "root"
+ group: "root"
+ creates: "/opt/netbox-{{ netbox_version }}"
+
+- name: Link NetBox distro to working dir
+ file:
+ state: "link"
+ src: "/opt/netbox-{{ netbox_version }}"
+ dest: "{{ netbox_working_dir }}"
+
+- name: Fix media dir permissions
+ file:
+ path: "{{ netbox_media_dir }}"
+ owner: "{{ netbox_username }}"
+ state: "directory"
+ recurse: true
+
+- name: Add local_requirements.txt for netbox extensions
+ lineinfile:
+ line: "netbox-qrcode"
+ dest: "{{ netbox_working_dir }}/local_requirements.txt"
+ create: true
+ owner: "root"
+ group: "root"
+ mode: "0644"
+
+- name: Create NetBox configuration file
+ template:
+ src: "configuration.py.j2"
+ dest: "{{ netbox_working_dir }}/netbox/netbox/configuration.py"
+ owner: "root"
+ group: "{{ netbox_groupname }}"
+ mode: "0640"
+ notify:
+ - "restart-netbox"
+
+- name: Run Netbox upgrade.sh script
+ command:
+ cmd: "{{ netbox_working_dir }}/upgrade.sh"
+ chdir: "{{ netbox_working_dir }}"
+ creates: "{{ netbox_working_dir }}/venv"
+ notify:
+ - "restart-netbox"
+
+# need to create superuser here, per:
+#
+# https://netbox.readthedocs.io/en/stable/installation/3-netbox/#create-a-super-usero
+#
+# but ansible's django_manage module currently isn't idempotent:
+#
+# https://github.com/ansible/ansible/issues/29786
+
+- name: Create gunicorn configuration
+ template:
+ src: "gunicorn.py.j2"
+ dest: "{{ netbox_working_dir }}/gunicorn.py"
+ owner: "root"
+ group: "{{ netbox_groupname }}"
+ mode: "0644"
+ notify:
+ - "start-netbox"
+ - "restart-netbox"
diff --git a/templates/configuration.py.j2 b/templates/configuration.py.j2
new file mode 100644
index 0000000..de51076
--- /dev/null
+++ b/templates/configuration.py.j2
@@ -0,0 +1,260 @@
+{#
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+#}
+#########################
+# #
+# Required settings #
+# #
+#########################
+
+# This is a list of valid fully-qualified domain names (FQDNs) for the NetBox server. NetBox will not permit write
+# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
+#
+# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
+ALLOWED_HOSTS = [ {{ netbox_allowed_hosts | map('regex_replace', '^(.*)$', '"\\1"') | join(', ') }} ]
+
+# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters:
+# https://docs.djangoproject.com/en/stable/ref/settings/#databases
+DATABASE = {
+ 'NAME': '{{ netbox_pg_db }}', # Database name
+ 'USER': '{{ netbox_pg_db_username }}', # PostgreSQL username
+ 'PASSWORD': '{{ netbox_pg_db_password }}', # PostgreSQL password
+ 'HOST': 'localhost', # Database server
+ 'PORT': '', # Database port (leave blank for default)
+ 'CONN_MAX_AGE': 300, # Max database connection age
+}
+
+# Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate
+# configuration exists for each. Full connection details are required in both sections, and it is strongly recommended
+# to use two separate database IDs.
+REDIS = {
+ 'tasks': {
+ 'HOST': 'localhost',
+ 'PORT': 6379,
+ # Comment out `HOST` and `PORT` lines and uncomment the following if using Redis Sentinel
+ # 'SENTINELS': [('mysentinel.redis.example.com', 6379)],
+ # 'SENTINEL_SERVICE': 'netbox',
+ 'PASSWORD': '',
+ 'DATABASE': 0,
+ 'DEFAULT_TIMEOUT': 300,
+ 'SSL': False,
+ },
+ 'caching': {
+ 'HOST': 'localhost',
+ 'PORT': 6379,
+ # Comment out `HOST` and `PORT` lines and uncomment the following if using Redis Sentinel
+ # 'SENTINELS': [('mysentinel.redis.example.com', 6379)],
+ # 'SENTINEL_SERVICE': 'netbox',
+ 'PASSWORD': '',
+ 'DATABASE': 1,
+ 'DEFAULT_TIMEOUT': 300,
+ 'SSL': False,
+ }
+}
+
+# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
+# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
+# symbols. NetBox will not run without this defined. For more information, see
+# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
+SECRET_KEY = '{{ netbox_secret_key }}'
+
+
+#########################
+# #
+# Optional settings #
+# #
+#########################
+
+# Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
+# application errors (assuming correct email settings are provided).
+ADMINS = [
+ # ['John Doe', 'jdoe@example.com'],
+]
+
+# URL schemes that are allowed within links in NetBox
+ALLOWED_URL_SCHEMES = (
+ 'file', 'ftp', 'ftps', 'http', 'https', 'irc', 'mailto', 'sftp', 'ssh', 'tel', 'telnet', 'tftp', 'vnc', 'xmpp',
+)
+
+# Optionally display a persistent banner at the top and/or bottom of every page. HTML is allowed. To display the same
+# content in both banners, define BANNER_TOP and set BANNER_BOTTOM = BANNER_TOP.
+BANNER_TOP = ''
+BANNER_BOTTOM = ''
+
+# Text to include on the login page above the login form. HTML is allowed.
+BANNER_LOGIN = ''
+
+# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
+# BASE_PATH = 'netbox/'
+BASE_PATH = ''
+
+# Cache timeout in seconds. Set to 0 to dissable caching. Defaults to 900 (15 minutes)
+CACHE_TIMEOUT = 900
+
+# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
+CHANGELOG_RETENTION = 90
+
+# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
+# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
+# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
+CORS_ORIGIN_ALLOW_ALL = False
+CORS_ORIGIN_WHITELIST = [
+ # 'https://hostname.example.com',
+]
+CORS_ORIGIN_REGEX_WHITELIST = [
+ # r'^(https?://)?(\w+\.)?example\.com$',
+]
+
+# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
+# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
+# on a production system.
+DEBUG = False
+
+# Email settings
+EMAIL = {
+ 'SERVER': 'localhost',
+ 'PORT': 25,
+ 'USERNAME': '',
+ 'PASSWORD': '',
+ 'USE_SSL': False,
+ 'USE_TLS': False,
+ 'TIMEOUT': 10, # seconds
+ 'FROM_EMAIL': '',
+}
+
+# Enforcement of unique IP space can be toggled on a per-VRF basis. To enforce unique IP space within the global table
+# (all prefixes and IP addresses not assigned to a VRF), set ENFORCE_GLOBAL_UNIQUE to True.
+ENFORCE_GLOBAL_UNIQUE = False
+
+# Exempt certain models from the enforcement of view permissions. Models listed here will be viewable by all users and
+# by anonymous users. List models in the form `<app>.<model>`. Add '*' to this list to exempt all models.
+EXEMPT_VIEW_PERMISSIONS = [
+ # 'dcim.site',
+ # 'dcim.region',
+ # 'ipam.prefix',
+]
+
+# HTTP proxies NetBox should use when sending outbound HTTP requests (e.g. for webhooks).
+# HTTP_PROXIES = {
+# 'http': 'http://10.10.1.10:3128',
+# 'https': 'http://10.10.1.10:1080',
+# }
+
+# IP addresses recognized as internal to the system. The debugging toolbar will be available only to clients accessing
+# NetBox from an internal IP.
+INTERNAL_IPS = ('127.0.0.1', '::1')
+
+# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
+# https://docs.djangoproject.com/en/stable/topics/logging/
+LOGGING = {}
+
+# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
+# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
+LOGIN_REQUIRED = False
+
+# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
+# re-authenticate. (Default: 1209600 [14 days])
+LOGIN_TIMEOUT = None
+
+# Setting this to True will display a "maintenance mode" banner at the top of every page.
+MAINTENANCE_MODE = False
+
+# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
+# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
+# all objects by specifying "?limit=0".
+MAX_PAGE_SIZE = 1000
+
+# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that
+# the default value of this setting is derived from the installed location.
+MEDIA_ROOT = '{{ netbox_media_dir }}'
+
+# By default uploaded media is stored on the local filesystem. Using Django-storages is also supported. Provide the
+# class path of the storage driver in STORAGE_BACKEND and any configuration options in STORAGE_CONFIG. For example:
+# STORAGE_BACKEND = 'storages.backends.s3boto3.S3Boto3Storage'
+# STORAGE_CONFIG = {
+# 'AWS_ACCESS_KEY_ID': 'Key ID',
+# 'AWS_SECRET_ACCESS_KEY': 'Secret',
+# 'AWS_STORAGE_BUCKET_NAME': 'netbox',
+# 'AWS_S3_REGION_NAME': 'eu-west-1',
+# }
+
+# Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
+METRICS_ENABLED = False
+
+# Credentials that NetBox will uses to authenticate to devices when connecting via NAPALM.
+NAPALM_USERNAME = ''
+NAPALM_PASSWORD = ''
+
+# NAPALM timeout (in seconds). (Default: 30)
+NAPALM_TIMEOUT = 30
+
+# NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
+# be provided as a dictionary.
+NAPALM_ARGS = {}
+
+# Determine how many objects to display per page within a list. (Default: 50)
+PAGINATE_COUNT = 50
+
+# Enable installed plugins. Add the name of each plugin to the list.
+PLUGINS = [
+ 'netbox_qrcode',
+]
+
+# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
+# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
+# PLUGINS_CONFIG = {
+# 'my_plugin': {
+# 'foo': 'bar',
+# 'buzz': 'bazz'
+# }
+# }
+
+# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
+# prefer IPv4 instead.
+PREFER_IPV4 = False
+
+# Rack elevation size defaults, in pixels. For best results, the ratio of width to height should be roughly 10:1.
+RACK_ELEVATION_DEFAULT_UNIT_HEIGHT = 22
+RACK_ELEVATION_DEFAULT_UNIT_WIDTH = 220
+
+# Remote authentication support
+REMOTE_AUTH_ENABLED = False
+REMOTE_AUTH_BACKEND = 'netbox.authentication.RemoteUserBackend'
+REMOTE_AUTH_HEADER = 'HTTP_REMOTE_USER'
+REMOTE_AUTH_AUTO_CREATE_USER = True
+REMOTE_AUTH_DEFAULT_GROUPS = []
+REMOTE_AUTH_DEFAULT_PERMISSIONS = {}
+
+# This determines how often the GitHub API is called to check the latest release of NetBox. Must be at least 1 hour.
+RELEASE_CHECK_TIMEOUT = 24 * 3600
+
+# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
+# version check or use the URL below to check for release in the official NetBox repository.
+RELEASE_CHECK_URL = None
+# RELEASE_CHECK_URL = 'https://api.github.com/repos/netbox-community/netbox/releases'
+
+# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
+# this setting is derived from the installed location.
+# REPORTS_ROOT = '/opt/netbox/netbox/reports'
+
+# The file path where custom scripts will be stored. A trailing slash is not needed. Note that the default value of
+# this setting is derived from the installed location.
+# SCRIPTS_ROOT = '/opt/netbox/netbox/scripts'
+
+# By default, NetBox will store session data in the database. Alternatively, a file path can be specified here to use
+# local file storage instead. (This can be useful for enabling authentication on a standby instance with read-only
+# database access.) Note that the user as which NetBox runs must have read and write permissions to this path.
+SESSION_FILE_PATH = None
+
+# Time zone (default: UTC)
+TIME_ZONE = 'UTC'
+
+# Date/time formatting. See the following link for supported formats:
+# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date
+DATE_FORMAT = 'N j, Y'
+SHORT_DATE_FORMAT = 'Y-m-d'
+TIME_FORMAT = 'g:i a'
+SHORT_TIME_FORMAT = 'H:i:s'
+DATETIME_FORMAT = 'N j, Y g:i a'
+SHORT_DATETIME_FORMAT = 'Y-m-d H:i'
diff --git a/templates/gunicorn.py.j2 b/templates/gunicorn.py.j2
new file mode 100644
index 0000000..dc7f2f6
--- /dev/null
+++ b/templates/gunicorn.py.j2
@@ -0,0 +1,20 @@
+{#
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+#}
+# The IP address (typically localhost) and port that the Netbox WSGI process should listen on
+bind = 'localhost:8001'
+
+# Number of gunicorn workers to spawn. This should typically be 2n+1, where
+# n is the number of CPU cores present.
+workers = {{ ansible_processor_vcpus + 1 }}
+
+# Number of threads per worker process
+threads = 3
+
+# Timeout (in seconds) for a request to complete
+timeout = 120
+
+# The maximum number of requests a worker can handle before being respawned
+max_requests = 5000
+max_requests_jitter = 500
diff --git a/templates/netbox-rq.service.j2 b/templates/netbox-rq.service.j2
new file mode 100644
index 0000000..1973d61
--- /dev/null
+++ b/templates/netbox-rq.service.j2
@@ -0,0 +1,25 @@
+{#
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+#}
+[Unit]
+Description=NetBox Request Queue Worker
+Documentation=https://netbox.readthedocs.io/en/stable/
+After=network-online.target
+Wants=network-online.target
+
+[Service]
+Type=simple
+
+User={{ netbox_username }}
+Group={{ netbox_groupname }}
+WorkingDirectory={{ netbox_working_dir }}
+
+ExecStart={{ netbox_working_dir }}/venv/bin/python3 {{ netbox_working_dir }}/netbox/manage.py rqworker
+
+Restart=on-failure
+RestartSec=30
+PrivateTmp=true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/templates/netbox.service.j2 b/templates/netbox.service.j2
new file mode 100644
index 0000000..df90bc5
--- /dev/null
+++ b/templates/netbox.service.j2
@@ -0,0 +1,26 @@
+{#
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+#}
+[Unit]
+Description=NetBox WSGI Service
+Documentation=https://netbox.readthedocs.io/en/stable/
+After=network-online.target
+Wants=network-online.target
+
+[Service]
+Type=simple
+
+User={{ netbox_username }}
+Group={{ netbox_groupname }}
+PIDFile=/var/tmp/netbox.pid
+WorkingDirectory={{ netbox_working_dir }}
+
+ExecStart={{ netbox_working_dir }}/venv/bin/gunicorn --pid /var/tmp/netbox.pid --pythonpath {{ netbox_working_dir }}/netbox --config {{ netbox_working_dir }}/gunicorn.py netbox.wsgi
+
+Restart=on-failure
+RestartSec=30
+PrivateTmp=true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/vars/Debian.yml b/vars/Debian.yml
new file mode 100644
index 0000000..3fad35c
--- /dev/null
+++ b/vars/Debian.yml
@@ -0,0 +1,11 @@
+---
+# netbox vars/Debian.yml
+#
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+#
+# NOTE: Only put platform/OS-specific variables in this file.
+# Put all other variables in the 'defaults/main.yml' file.
+
+# shell used by the netbox user (non-interactive)
+netbox_shell: "/usr/sbin/nologin"