-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
main.yml
133 lines (114 loc) · 3.88 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
# tasks file for lae.netbox
- import_tasks: validate_variables.yml
- import_tasks: load_variables.yml
- include_tasks: "install_packages_{{ ansible_pkg_mgr }}.yml"
- name: Switch Ansible's Python interpreter to Python 3
set_fact:
ansible_python_interpreter: "{{ netbox_python_binary }}"
- name: Recheck new Python interpreter's version
setup:
gather_subset: min
filter: ansible_python_version
# Can't quite check the effective version of a git installation this early since
# the repo isn't checked out, but most users will be on develop in the first
# place so this dumb check should be good enough.
- name: Ensure Python version installed is compatible with this version of Netbox
assert:
that:
- "ansible_python_version is version(item.python_needed, '>=')"
msg: >
NetBox {{ item.netbox_version_min }} requires at least Python {{ item.python_needed }}.
Please either specify an older NetBox version, upgrade to a newer
distribution that provides Python at least {{ item.python_needed }}, or
set netbox_python_binary to an appropriate Python {{ item.python_needed }} binary.
when:
- netbox_stable and netbox_stable_version is version(item.netbox_version_min, '>=') or netbox_git
loop: "{{ netbox_python_compat_matrix }}"
- name: Create NetBox user group
group:
name: "{{ netbox_group }}"
- name: Create NetBox user and home directory
user:
name: "{{ netbox_user }}"
group: "{{ netbox_group }}"
home: "{{ netbox_home }}"
- name: Ensure Postgres database exists (via socket)
postgresql_db:
name: "{{ netbox_database }}"
login_user: "{{ netbox_database_user }}"
login_unix_socket: "{{ netbox_database_socket }}"
become: true
become_user: "{{ netbox_database_user }}"
when:
- netbox_database_socket is defined
- netbox_database_host is not defined
- name: Ensure Postgres database exists (via TCP)
postgresql_db:
name: "{{ netbox_database }}"
login_host: "{{ netbox_database_host }}"
port: "{{ netbox_database_port }}"
login_user: "{{ netbox_database_user }}"
login_password: "{{ netbox_database_password }}"
when:
- netbox_database_socket is not defined
- netbox_database_host is defined
- import_tasks: deploy_netbox.yml
- name: Install uWSGI via pip
pip:
name: uwsgi
state: "{{ 'latest' if netbox_keep_uwsgi_updated else 'present' }}"
umask: "0022"
environment:
PATH: "/usr/local/bin:{{ _path }}"
notify:
- reload netbox.service
retries: 2
register: _netbox_uwsgi_install
until: _netbox_uwsgi_install is succeeded
- name: Configure uWSGI NetBox application
template:
src: uwsgi.ini.j2
dest: "{{ netbox_shared_path }}/uwsgi.ini"
owner: "{{ netbox_user }}"
group: "{{ netbox_group }}"
notify:
- reload netbox.service
- name: Install NetBox socket unit file
template:
src: netbox.socket.j2
dest: /lib/systemd/system/netbox.socket
notify:
- restart netbox.socket
- name: Install NetBox service unit file
template:
src: netbox.service.j2
dest: /lib/systemd/system/netbox.service
notify:
- restart netbox.service
- name: Install NetBox-rqworker service unit file
template:
src: netbox-rqworker.service.j2
dest: /lib/systemd/system/netbox-rqworker.service
notify:
- restart netbox-rqworker.service
- name: Start and enable NetBox' socket and service
systemd:
name: "{{ item }}"
state: started
enabled: true
loop:
- netbox.socket
- netbox.service
- name: Start and enable netbox-rqworker.service
systemd:
name: netbox-rqworker.service
state: started
enabled: true
- name: Restore the previous Ansible Python interpreter
set_fact:
ansible_python_interpreter: "{{ _netbox_global_python if _netbox_global_python is defined else 'auto_legacy' }}"
- name: Recheck the previous Python interpreter's version
setup:
gather_subset: min
filter: ansible_python_version