|
|
@ -0,0 +1,165 @@ |
|
|
|
- name: install postgres |
|
|
|
apt: |
|
|
|
package: [postgresql, libpq-dev, python-psycopg2] |
|
|
|
state: present |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: create netbox database |
|
|
|
postgresql_db: |
|
|
|
name: "{{netbox_db}}" |
|
|
|
state: present |
|
|
|
become: yes |
|
|
|
become_user: postgres |
|
|
|
|
|
|
|
- name: create netbox postgres user |
|
|
|
postgresql_user: |
|
|
|
db: "{{netbox_db}}" |
|
|
|
name: "{{netbox_pg_username}}" |
|
|
|
password: "{{netbox_pg_password}}" |
|
|
|
become: yes |
|
|
|
become_user: postgres |
|
|
|
|
|
|
|
- name: install dependencies |
|
|
|
apt: |
|
|
|
package: [python3, python3-setuptools, python-setuptools, python3-dev, build-essential, libxml2-dev, libxslt1-dev, |
|
|
|
libffi-dev, graphviz, libpq-dev, libssl-dev, redis-server, zlib1g-dev, libopenjp2-7, supervisor, nginx] |
|
|
|
state: present |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: remove system pip |
|
|
|
apt: |
|
|
|
package: python3-pip |
|
|
|
state: absent |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: install pip via get-pip.py |
|
|
|
shell: curl https://bootstrap.pypa.io/get-pip.py | python3 - |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: grab the netbox release |
|
|
|
unarchive: |
|
|
|
src: https://github.com/digitalocean/netbox/archive/v{{netbox_release}}.tar.gz |
|
|
|
remote_src: yes |
|
|
|
dest: /opt |
|
|
|
owner: root |
|
|
|
group: root |
|
|
|
mode: u=rwX,g=rX,o=rX |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: alias it to /opt/netbox |
|
|
|
file: |
|
|
|
src: /opt/netbox-{{netbox_release}} |
|
|
|
dest: /opt/netbox |
|
|
|
state: link |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: create netbox user |
|
|
|
user: |
|
|
|
name: "{{netbox_user}}" |
|
|
|
state: present |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: chown netbox/media to netbox user |
|
|
|
file: |
|
|
|
path: /opt/netbox/netbox/media |
|
|
|
recurse: yes |
|
|
|
owner: "{{netbox_user}}" |
|
|
|
group: "{{netbox_user}}" |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: install dependencies via pip |
|
|
|
pip: |
|
|
|
requirements: /opt/netbox/requirements.txt |
|
|
|
executable: pip3 |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: install napalm, Pillow, gunicorn |
|
|
|
pip: |
|
|
|
name: [napalm, Pillow, gunicorn] |
|
|
|
state: present |
|
|
|
executable: pip3 |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: template netbox config |
|
|
|
template: |
|
|
|
src: netbox/configuration.py |
|
|
|
dest: /opt/netbox/netbox/netbox/configuration.py |
|
|
|
owner: "{{netbox_user}}" |
|
|
|
group: "{{netbox_user}}" |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: run migrations |
|
|
|
shell: python3 manage.py migrate |
|
|
|
args: |
|
|
|
chdir: /opt/netbox/netbox/ |
|
|
|
become: yes |
|
|
|
become_user: "{{netbox_user}}" |
|
|
|
|
|
|
|
- name: create netbox superuser |
|
|
|
shell: > |
|
|
|
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('{{netbox_superuser_username}}', '{{netbox_superuser_email}}', '{{netbox_superuser_password}}')" \ |
|
|
|
| python3 manage.py shell |
|
|
|
args: |
|
|
|
chdir: /opt/netbox/netbox/ |
|
|
|
become: yes |
|
|
|
become_user: "{{netbox_user}}" |
|
|
|
|
|
|
|
- name: collect static files |
|
|
|
shell: python3 manage.py collectstatic --no-input |
|
|
|
args: |
|
|
|
chdir: /opt/netbox/netbox/ |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: load seed data |
|
|
|
shell: python3 manage.py loaddata initial_data |
|
|
|
args: |
|
|
|
chdir: /opt/netbox/netbox/ |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: template nginx config |
|
|
|
template: |
|
|
|
src: nginx/netbox.conf |
|
|
|
dest: /etc/nginx/sites-available/netbox |
|
|
|
owner: root |
|
|
|
group: root |
|
|
|
mode: 0644 |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: link nginx config |
|
|
|
file: |
|
|
|
src: /etc/nginx/sites-available/netbox |
|
|
|
dest: /etc/nginx/sites-enabled/netbox |
|
|
|
state: link |
|
|
|
owner: root |
|
|
|
group: root |
|
|
|
mode: 0644 |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: install gunicorn config |
|
|
|
template: |
|
|
|
src: netbox/gunicorn_config.py |
|
|
|
dest: /opt/netbox/gunicorn_config.py |
|
|
|
owner: "{{netbox_user}}" |
|
|
|
group: "{{netbox_user}}" |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: install gunicorn supervisord config |
|
|
|
template: |
|
|
|
src: supervisor/netbox.conf |
|
|
|
dest: /etc/supervisor/conf.d/netbox.conf |
|
|
|
owner: root |
|
|
|
group: root |
|
|
|
mode: 0644 |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: restart supervisord |
|
|
|
service: |
|
|
|
name: supervisor |
|
|
|
state: restarted |
|
|
|
become: yes |
|
|
|
|
|
|
|
- name: restart nginx |
|
|
|
service: |
|
|
|
name: nginx |
|
|
|
state: restarted |
|
|
|
become: yes |