add netbox role for ensuring netbox is deployed as specified

The role takes over the deployment of netbox and its dependencies, while
still requiring the user to provide the netbox version, db password and
config as well as to set up a web server and handle stuff like creating
users, etc.
This commit is contained in:
June 2025-02-14 21:43:44 +01:00
commit 783c36bcc1
Signed by: june
SSH key fingerprint: SHA256:o9EAq4Y9N9K0pBQeBTqhSDrND5E7oB+60ZNx0U1yPe0
5 changed files with 227 additions and 0 deletions

View file

@ -0,0 +1,103 @@
- name: Ensure all dependencies are installed
ansible.builtin.apt:
name:
- python3
- python3-pip
- python3-venv
- python3-dev
- build-essential
- libxml2-dev
- libxslt1-dev
- libffi-dev
- libpq-dev
- libssl-dev
- zlib1g-dev
- git
become: true
- name: Ensure NetBox source is present
ansible.builtin.git:
repo: https://github.com/netbox-community/netbox.git
dest: /opt/netbox/
version: "{{ netbox__version }}"
become: true
notify:
- Run upgrade script
- Ensure netbox systemd services are set up and up-to-date
- name: Ensure netbox user
block:
- name: Ensure netbox group exists
ansible.builtin.group:
name: netbox
system: true
become: true
- name: Ensure netbox user exists
ansible.builtin.user:
name: netbox
group: netbox
password: '!'
system: true
become: true
- name: Ensure relevant directories are owned by netbox user
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: netbox
recurse: true
become: true
loop:
- "/opt/netbox/netbox/media/"
- "/opt/netbox/netbox/reports/"
- "/opt/netbox/netbox/scripts/"
- name: Deploy configuration.py
ansible.builtin.copy:
content: "{{ netbox__config }}"
dest: "/opt/netbox/netbox/netbox/configuration.py"
mode: "0644"
owner: root
group: root
become: true
notify: Ensure netbox systemd services are set up and up-to-date
- name: Ensure provided gunicorn config is copied
ansible.builtin.copy:
remote_src: true
src: "/opt/netbox/contrib/gunicorn.py"
dest: "/opt/netbox/gunicorn.py"
mode: "0644"
owner: root
group: root
become: true
notify: Ensure netbox systemd services are set up and up-to-date
- name: Ensure provided netbox systemd service files are copied
ansible.builtin.copy:
remote_src: true
src: "/opt/netbox/contrib/{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
mode: "0644"
owner: root
group: root
become: true
loop:
- "netbox.service"
- "netbox-rq.service"
notify: Ensure netbox systemd services are set up and up-to-date
- name: Ensure provided housekeeping systemd service and timer are copied
ansible.builtin.copy:
remote_src: true
src: "/opt/netbox/contrib/{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
mode: "0644"
owner: root
group: root
become: true
loop:
- "netbox-housekeeping.service"
- "netbox-housekeeping.timer"
notify: Ensure netbox housekeeping timer is set up and up-to-date