blob: 71ac5929906c202ccd31d3b88844879b082bf991 [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"
Zack Williams38e28f92020-10-09 23:42:21 -070063 mode: "u+rwX,go+rX" # 755 on dirs, 644 on files
Zack Williams048c6832020-08-02 21:14:35 -070064 recurse: true
65
66- name: Add local_requirements.txt for netbox extensions
67 lineinfile:
68 line: "netbox-qrcode"
69 dest: "{{ netbox_working_dir }}/local_requirements.txt"
70 create: true
71 owner: "root"
72 group: "root"
73 mode: "0644"
74
75- name: Create NetBox configuration file
76 template:
77 src: "configuration.py.j2"
78 dest: "{{ netbox_working_dir }}/netbox/netbox/configuration.py"
79 owner: "root"
80 group: "{{ netbox_groupname }}"
81 mode: "0640"
82 notify:
83 - "restart-netbox"
84
85- name: Run Netbox upgrade.sh script
86 command:
87 cmd: "{{ netbox_working_dir }}/upgrade.sh"
88 chdir: "{{ netbox_working_dir }}"
89 creates: "{{ netbox_working_dir }}/venv"
90 notify:
91 - "restart-netbox"
92
93# need to create superuser here, per:
94#
95# https://netbox.readthedocs.io/en/stable/installation/3-netbox/#create-a-super-usero
96#
97# but ansible's django_manage module currently isn't idempotent:
98#
99# https://github.com/ansible/ansible/issues/29786
100
101- name: Create gunicorn configuration
102 template:
103 src: "gunicorn.py.j2"
104 dest: "{{ netbox_working_dir }}/gunicorn.py"
105 owner: "root"
106 group: "{{ netbox_groupname }}"
107 mode: "0644"
108 notify:
109 - "start-netbox"
110 - "restart-netbox"