blob: 71ac5929906c202ccd31d3b88844879b082bf991 [file] [log] [blame]
---
# 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"
mode: "u+rwX,go+rX" # 755 on dirs, 644 on files
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"