Initial work on netbox role
Change-Id: I8e51dc7d5f21d3c83b3d8ab3955467c6069c7c74
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"