From 279b26964aecf1cef5aa02b51677511e5c0f2145 Mon Sep 17 00:00:00 2001 From: Julian Rother Date: Thu, 9 Jan 2025 23:44:03 +0100 Subject: [PATCH] Initial commit --- defaults/main.yml | 12 ++++++++++ handlers/main.yml | 2 ++ tasks/main.yml | 44 +++++++++++++++++++++++++++++++++++ templates/configuration.py.j2 | 5 ++++ templates/gunicorn.conf.py.j2 | 5 ++++ 5 files changed, 68 insertions(+) create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/configuration.py.j2 create mode 100644 templates/gunicorn.conf.py.j2 diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..9fd2039 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,12 @@ +netbox_config: + # DATABASE: {...} + # REDIS: {...} + # SECRET_KEY: "..." + MEDIA_ROOT: /var/lib/netbox/media + REPORTS_ROOT: /var/lib/netbox/reports + SCRIPTS_ROOT: /var/lib/netbox/scripts + CENSUS_REPORTING_ENABLED: false +netbox_config_raw: '' + +netbox_gunicorn_config: {} +netbox_gunicorn_config_raw: '' diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..898a63f --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,2 @@ +- name: reconfigure netbox + ansible.builtin.command: dpkg-reconfigure netbox diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..fcaa99d --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,44 @@ +- name: Create netbox group + ansible.builtin.group: + name: netbox + system: true + +- name: Create netbox user + ansible.builtin.user: + name: netbox + group: netbox + groups: + - redis + home: /var/lib/netbox + create_home: false # Created by postinst + system: true + +- name: Create netbox config dir + ansible.builtin.file: + path: /etc/netbox + owner: root + group: netbox + mode: 0750 + state: directory + +- name: Create netbox config + ansible.builtin.template: + src: configuration.py.j2 + dest: /etc/netbox/configuration.py + owner: root + group: netbox + mode: '0640' + notify: + - reconfigure netbox + +- name: Create gunicorn config + ansible.builtin.template: + src: gunicorn.conf.py.j2 + dest: /etc/netbox/gunicorn.conf.py + owner: root + group: netbox + mode: '0640' + notify: + - reconfigure netbox + +# TODO: Build, fetch and install the deb (currently borrowed from KuKo and manually installed) diff --git a/templates/configuration.py.j2 b/templates/configuration.py.j2 new file mode 100644 index 0000000..5ce150a --- /dev/null +++ b/templates/configuration.py.j2 @@ -0,0 +1,5 @@ +{% for key, value in netbox_config.items() %} +{{ key }} = {{ value.__repr__() }} +{% endfor %} + +{{ netbox_config_raw }} diff --git a/templates/gunicorn.conf.py.j2 b/templates/gunicorn.conf.py.j2 new file mode 100644 index 0000000..947bfcb --- /dev/null +++ b/templates/gunicorn.conf.py.j2 @@ -0,0 +1,5 @@ +{% for key, value in netbox_gunicorn_config.items() %} +{{ key }} = {{ value.__repr__() }} +{% endfor %} + +{{ netbox_gunicorn_config_raw }}