blob: e4f2ada5f4a2491b614dce7e91c079b1a1f505e4 [file] [log] [blame]
Zack Williams048c6832020-08-02 21:14:35 -07001---
2# netbox tasks/main.yml
3#
4# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
5# SPDX-License-Identifier: Apache-2.0
6
7- name: include OS-specific vars
8 include_vars: "{{ ansible_os_family }}.yml"
9
10- name: include OS-specific tasks
11 include_tasks: "{{ ansible_os_family }}.yml"
12
13- name: Create group for NetBox
14 group:
15 name: "{{ netbox_groupname }}"
16
17- name: Create user for NetBox
18 user:
19 name: "{{ netbox_username }}"
20 group: "{{ netbox_groupname }}"
21 comment: "{{ netbox_comment }}"
22 shell: "{{ netbox_shell }}"
23 system: true
24 password_lock: true
25
26- name: Create NetBox dist dir
27 file:
28 path: "{{ netbox_dist_dir }}"
29 state: directory
30 owner: "root"
31 group: "root"
32 mode: "0755"
33
34- name: Download NetBox distribution .tgz file
35 get_url:
36 url: "https://github.com/netbox-community/netbox/archive/v{{ netbox_version }}.tar.gz"
37 dest: "{{ netbox_dist_dir }}/netbox_{{ netbox_version }}.tar.gz"
38 owner: "root"
39 group: "root"
40 mode: "0644"
41 checksum: "{{ netbox_version_checksum }}"
42
43- name: Unarchive NetBox distribution
44 unarchive:
45 remote_src: true
46 src: "{{ netbox_dist_dir }}/netbox_{{ netbox_version }}.tar.gz"
47 dest: "/opt"
48 owner: "root"
49 group: "root"
50 creates: "/opt/netbox-{{ netbox_version }}"
51
52- name: Link NetBox distro to working dir
53 file:
54 state: "link"
55 src: "/opt/netbox-{{ netbox_version }}"
56 dest: "{{ netbox_working_dir }}"
57
58- name: Fix media dir permissions
59 file:
60 path: "{{ netbox_media_dir }}"
61 owner: "{{ netbox_username }}"
62 state: "directory"
63 recurse: true
64
65- name: Add local_requirements.txt for netbox extensions
66 lineinfile:
67 line: "netbox-qrcode"
68 dest: "{{ netbox_working_dir }}/local_requirements.txt"
69 create: true
70 owner: "root"
71 group: "root"
72 mode: "0644"
73
74- name: Create NetBox configuration file
75 template:
76 src: "configuration.py.j2"
77 dest: "{{ netbox_working_dir }}/netbox/netbox/configuration.py"
78 owner: "root"
79 group: "{{ netbox_groupname }}"
80 mode: "0640"
81 notify:
82 - "restart-netbox"
83
84- name: Run Netbox upgrade.sh script
85 command:
86 cmd: "{{ netbox_working_dir }}/upgrade.sh"
87 chdir: "{{ netbox_working_dir }}"
88 creates: "{{ netbox_working_dir }}/venv"
89 notify:
90 - "restart-netbox"
91
92# need to create superuser here, per:
93#
94# https://netbox.readthedocs.io/en/stable/installation/3-netbox/#create-a-super-usero
95#
96# but ansible's django_manage module currently isn't idempotent:
97#
98# https://github.com/ansible/ansible/issues/29786
99
100- name: Create gunicorn configuration
101 template:
102 src: "gunicorn.py.j2"
103 dest: "{{ netbox_working_dir }}/gunicorn.py"
104 owner: "root"
105 group: "{{ netbox_groupname }}"
106 mode: "0644"
107 notify:
108 - "start-netbox"
109 - "restart-netbox"