From 5999de7be760732b69310565cc39d19ae215f9b9 Mon Sep 17 00:00:00 2001 From: Philipp Rintz <13933258+p-rintz@users.noreply.github.com> Date: Tue, 25 Jul 2023 21:07:51 +0200 Subject: [PATCH 01/10] Allow use of multiple rqworkers (#161) --- .gitignore | 1 + README.adoc | 9 +++++++++ defaults/main.yml | 1 + handlers/main.yml | 8 ++------ molecule/default/converge.yml | 1 + molecule/default/tests/test_default.py | 3 ++- tasks/deploy_netbox.yml | 2 +- tasks/main.yml | 5 +++-- templates/netbox-rqworker.service.j2 | 22 +++++++++++----------- tests/test.yml | 2 +- 10 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 69c335d..9e17f72 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.retry *.code-workspace *.sw? +.venv diff --git a/README.adoc b/README.adoc index 8e4568e..1fea1e6 100644 --- a/README.adoc +++ b/README.adoc @@ -234,6 +234,15 @@ Use this syntax if your redis is installed with sentinet architecture (multiple the second set of variables if you wish to split your cache database from your webhooks database. +[source,yaml] +---- +netbox_rqworker_processes: 1 +---- + +Specify how many request queue workers should be started by the systemd service. +You can leave this at the default of 1, unless you have a large number of reports, +scripts and other background tasks. + [source,yaml] ---- netbox_config: diff --git a/defaults/main.yml b/defaults/main.yml index fbc8286..4405bd8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -100,3 +100,4 @@ netbox_pip_constraints: netbox_keep_uwsgi_updated: false netbox_uwsgi_options: {} +netbox_rqworker_processes: 1 diff --git a/handlers/main.yml b/handlers/main.yml index f12fe30..84debbf 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -19,11 +19,7 @@ - name: restart netbox-rqworker.service systemd: - name: netbox-rqworker.service + name: "netbox-rqworker@{{ item }}.service" state: restarted daemon_reload: true - -- name: reload netbox-rqworker.service - systemd: - name: netbox-rqworker.service - state: reloaded + with_sequence: count="{{ netbox_rqworker_processes }}" diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 994c37c..f93a3f2 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -27,6 +27,7 @@ role_attr_flags: CREATEDB,NOSUPERUSER ## REDIS server install redis_bind: 127.0.0.1 + netbox_rqworker_processes: 2 roles: - geerlingguy.postgresql - davidwittman.redis diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index 7968eb9..073d89d 100644 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -10,7 +10,8 @@ def test_services(host): services = [ "netbox.socket", "netbox.service", - "netbox-rqworker.service" + "netbox-rqworker@1.service" + "netbox-rqworker@2.service" ] for service in services: s = host.service(service) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 3bc3e98..9a303af 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -80,7 +80,7 @@ py_compile.compile(f, c); os.remove(c)\"" notify: - reload netbox.service - - reload netbox-rqworker.service + - restart netbox-rqworker.service - name: Generate LDAP configuration for NetBox if enabled template: diff --git a/tasks/main.yml b/tasks/main.yml index b6a574d..f822b5a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -106,7 +106,7 @@ - name: Install NetBox-rqworker service unit file template: src: netbox-rqworker.service.j2 - dest: /lib/systemd/system/netbox-rqworker.service + dest: /lib/systemd/system/netbox-rqworker@.service notify: - restart netbox-rqworker.service @@ -121,9 +121,10 @@ - name: Start and enable netbox-rqworker.service systemd: - name: netbox-rqworker.service + name: "netbox-rqworker@{{ item }}.service" state: started enabled: true + with_sequence: count="{{ netbox_rqworker_processes }}" - name: Restore the previous Ansible Python interpreter set_fact: diff --git a/templates/netbox-rqworker.service.j2 b/templates/netbox-rqworker.service.j2 index 7937142..070fb7d 100644 --- a/templates/netbox-rqworker.service.j2 +++ b/templates/netbox-rqworker.service.j2 @@ -1,25 +1,25 @@ {{ ansible_managed | comment }} [Unit] -Description=NetBox RQ-Worker -Documentation=http://netbox.readthedocs.io/en/{{ 'latest' if netbox_git else 'stable' }}/installation/3-http-daemon/#supervisord-installation -After=syslog.target +Description=NetBox Request Queue Worker %i +Documentation=https://docs.netbox.dev/ +After=network-online.target +Wants=network-online.target [Service] +Type=simple + WorkingDirectory={{ netbox_shared_path }} -ExecStart={{ netbox_virtualenv_path }}/bin/python \ - {{ netbox_current_path }}/netbox/manage.py rqworker -ExecReload=/bin/kill -1 $MAINPID -ExecStop=/bin/kill -2 $MAINPID +ExecStart={{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py rqworker high default low + StandardOutput=journal StandardError=journal User={{ netbox_user }} Group={{ netbox_group }} Restart=on-failure -#SuccessExitStatus=15 17 29 30 -KillSignal=SIGQUIT -StandardError=syslog +RestartSec=30 + NotifyAccess=all -PrivateTmp=yes +PrivateTmp=true ProtectSystem=full DeviceAllow=/dev/null rw DeviceAllow=/dev/urandom r diff --git a/tests/test.yml b/tests/test.yml index be428f9..0acf9f9 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -13,7 +13,7 @@ shell: cat /srv/netbox/shared/uwsgi.ini changed_when: false - name: NetBox rq-worker service status # noqa 303 305 - shell: "systemctl status netbox-rqworker.service" + shell: "systemctl status netbox-rqworker@1.service" changed_when: false - name: NetBox application log # noqa 305 shell: cat /srv/netbox/shared/application.log From 8854899ae29168c1956ed60ba11c128fd2cc2ec5 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Fri, 22 Sep 2023 12:43:28 +0200 Subject: [PATCH 02/10] Add vars file for Debian 12 --- vars/debian-12.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 vars/debian-12.yml diff --git a/vars/debian-12.yml b/vars/debian-12.yml new file mode 100644 index 0000000..775e7c0 --- /dev/null +++ b/vars/debian-12.yml @@ -0,0 +1,20 @@ +--- +_netbox_packages: + - libxml2-dev + - libxslt1-dev + - libffi-dev + - libjpeg-dev + - graphviz + - libpq-dev + - libssl-dev + - systemd-cron +_netbox_python_packages: + - python3.11 + - python3.11-dev + - python3-venv + - python3-pip + - python3-psycopg2 # used by ansible's postgres modules +_netbox_python_binary: /usr/bin/python3 +_netbox_ldap_packages: + - libldap2-dev + - libsasl2-dev From a9b61473f80e3d6e12f8131716f9baf9b4e78fdd Mon Sep 17 00:00:00 2001 From: David Mehren Date: Fri, 22 Sep 2023 12:44:31 +0200 Subject: [PATCH 03/10] Add a workaround for installing system-wide pip packages on Debian 12 --- tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/main.yml b/tasks/main.yml index f822b5a..99d95b9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -72,6 +72,7 @@ name: uwsgi state: "{{ 'latest' if netbox_keep_uwsgi_updated else 'present' }}" umask: "0022" + extra_args: "{{ (ansible_distribution_release == 'bookworm') | ternary('--break-system-packages', '') }}" environment: PATH: "/usr/local/bin:{{ _path }}" notify: From e2b8dec0ee26cd45567f64dc2a4685d7665b1a01 Mon Sep 17 00:00:00 2001 From: Tyler Bigler <17618971+tyler-8@users.noreply.github.com> Date: Wed, 11 Jan 2023 19:11:49 -0500 Subject: [PATCH 04/10] Allow optional install of uwsgi into Netbox venv --- README.adoc | 9 +++++++++ defaults/main.yml | 1 + tasks/load_variables.yml | 5 +++++ tasks/main.yml | 1 + templates/netbox.service.j2 | 2 +- vars/main.yml | 2 ++ 6 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 6371c1d..690430a 100644 --- a/README.adoc +++ b/README.adoc @@ -418,6 +418,15 @@ netbox_uwsgi_options: {} Specify extra configuration options to insert into `uwsgi.ini` here. This is expected to be a dictionary of key/value pairs, e.g. `buffer-size: 65535`. +[source,yaml] +netbox_uwsgi_in_venv: false + +Toggle `netbox_uwsgi_in_venv` to `true` if you want `uwsgi` to be installed in the same virtual environment as NetBox. +Otherwise, it will be installed system-wide into the library path of the python version used to created the virtual environment (normal/legacy behavior). + +WARNING: There's a possibility that this may become the default in a later version of this role (I think after further cross-platform testing). +See https://github.com/lae/ansible-role-netbox/issues/144[issue #144] for further details. + [source,yaml] netbox_install_epel: true diff --git a/defaults/main.yml b/defaults/main.yml index e1f5f62..f3d8410 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -98,4 +98,5 @@ netbox_pip_constraints: # - 'MarkupSafe<2.1.0' netbox_keep_uwsgi_updated: false +netbox_uwsgi_in_venv: false netbox_uwsgi_options: {} diff --git a/tasks/load_variables.yml b/tasks/load_variables.yml index c177431..7093067 100644 --- a/tasks/load_variables.yml +++ b/tasks/load_variables.yml @@ -59,3 +59,8 @@ set_fact: _netbox_global_python: "{{ ansible_python_interpreter }}" when: ansible_python_interpreter is defined + +- name: Set the execution uwsgi command + set_fact: + netbox_uwsgi_cmd: "/usr/bin/env uwsgi" + when: "not netbox_uwsgi_in_venv | bool" diff --git a/tasks/main.yml b/tasks/main.yml index ae917cd..6cb4297 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -70,6 +70,7 @@ name: uwsgi state: "{{ 'latest' if netbox_keep_uwsgi_updated else 'present' }}" umask: "0022" + virtualenv: "{{ omit if not netbox_uwsgi_in_venv else netbox_virtualenv_path }}" environment: PATH: "/usr/local/bin:{{ _path }}" notify: diff --git a/templates/netbox.service.j2 b/templates/netbox.service.j2 index dfd717e..32e110c 100644 --- a/templates/netbox.service.j2 +++ b/templates/netbox.service.j2 @@ -6,7 +6,7 @@ Requires=netbox.socket After=syslog.target [Service] -ExecStart=/usr/bin/env uwsgi --ini {{ netbox_shared_path }}/uwsgi.ini +ExecStart={{ netbox_uwsgi_cmd }} --ini {{ netbox_shared_path }}/uwsgi.ini ExecReload=/bin/kill -1 $MAINPID ExecStop=/bin/kill -2 $MAINPID StandardInput=socket diff --git a/vars/main.yml b/vars/main.yml index 17c39de..f2d7d7f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -2,6 +2,7 @@ # vars file for lae.netbox netbox_config_path: "{{ netbox_current_path }}/netbox/netbox" netbox_virtualenv_path: "{{ netbox_current_path }}/venv-py3" +netbox_uwsgi_cmd: "{{ netbox_virtualenv_path }}/bin/uwsgi" _netbox_storages_map: s3boto3: boto3 @@ -43,3 +44,4 @@ netbox_superuser_token: | netbox_python_compat_matrix: - { netbox_version_min: '2.8.0', python_needed: '3.6.0' } - { netbox_version_min: '3.0.0', python_needed: '3.7.0' } + - { netbox_version_min: '3.2.0', python_needed: '3.8.0' } From ef0b0791a39d0536025d3c6389849b51048de266 Mon Sep 17 00:00:00 2001 From: "Simon Leinen (SWITCH)" Date: Sun, 5 Nov 2023 15:32:07 +0100 Subject: [PATCH 05/10] Install uWSGI in venv --- tasks/main.yml | 1 - vars/debian-12.yml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 99d95b9..f822b5a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -72,7 +72,6 @@ name: uwsgi state: "{{ 'latest' if netbox_keep_uwsgi_updated else 'present' }}" umask: "0022" - extra_args: "{{ (ansible_distribution_release == 'bookworm') | ternary('--break-system-packages', '') }}" environment: PATH: "/usr/local/bin:{{ _path }}" notify: diff --git a/vars/debian-12.yml b/vars/debian-12.yml index 775e7c0..65a3d78 100644 --- a/vars/debian-12.yml +++ b/vars/debian-12.yml @@ -18,3 +18,4 @@ _netbox_python_binary: /usr/bin/python3 _netbox_ldap_packages: - libldap2-dev - libsasl2-dev +netbox_uwsgi_in_venv: true From f9288b241d58473f77c99312b901dde5fa7f5e15 Mon Sep 17 00:00:00 2001 From: "Simon Leinen (SWITCH)" Date: Sun, 5 Nov 2023 16:12:51 +0100 Subject: [PATCH 06/10] Run "git log" under the same user that cloned the repo This avoids "fatal: detected dubious ownership in repository" errors that cause all feature-detection commands to fail. --- tasks/install_via_git.yml | 133 ++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 64 deletions(-) diff --git a/tasks/install_via_git.yml b/tasks/install_via_git.yml index 7e3afda..69a64f0 100644 --- a/tasks/install_via_git.yml +++ b/tasks/install_via_git.yml @@ -15,77 +15,82 @@ group: "{{ netbox_group }}" state: directory -- name: Check existence of commit 1fb67b7, fixing issue netbox#2239 - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^1fb67b791f1a91c624dae4a1cd256e4cf3ddbb77' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_issue_2239_fix - changed_when: false - failed_when: "_netbox_git_contains_issue_2239_fix.rc not in [0, 1]" +- name: Check for presence of various commits in git history + block: + - name: Check existence of commit 1fb67b7, fixing issue netbox#2239 + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^1fb67b791f1a91c624dae4a1cd256e4cf3ddbb77' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_issue_2239_fix + changed_when: false + failed_when: "_netbox_git_contains_issue_2239_fix.rc not in [0, 1]" -- name: Check existence of commit 3590ed3, renaming webhooks to tasks - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^3590ed378d161dd724fad2dc73ff56da746352f8' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_tasks_rename - changed_when: false - failed_when: "_netbox_git_contains_tasks_rename.rc not in [0, 1]" + - name: Check existence of commit 3590ed3, renaming webhooks to tasks + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^3590ed378d161dd724fad2dc73ff56da746352f8' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_tasks_rename + changed_when: false + failed_when: "_netbox_git_contains_tasks_rename.rc not in [0, 1]" -- name: Check existence of commit 90dbe9b, renaming DEFAULT_TIMEOUT to RQ_DEFAULT_TIMEOUT - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^90dbe9bf60ab3c72be10fd070c65c26dca543ca5' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_rq_timeout - changed_when: False - failed_when: "_netbox_git_contains_rq_timeout.rc not in [0, 1]" + - name: Check existence of commit 90dbe9b, renaming DEFAULT_TIMEOUT to RQ_DEFAULT_TIMEOUT + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^90dbe9bf60ab3c72be10fd070c65c26dca543ca5' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_rq_timeout + changed_when: False + failed_when: "_netbox_git_contains_rq_timeout.rc not in [0, 1]" -- name: Check existence of commit f560693, introducing trace_paths management command - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^f560693748d1f35e79ad9d006a8a9b75ef5ae37b' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_trace_paths - changed_when: False - failed_when: "_netbox_git_contains_trace_paths.rc not in [0, 1]" + - name: Check existence of commit f560693, introducing trace_paths management command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^f560693748d1f35e79ad9d006a8a9b75ef5ae37b' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_trace_paths + changed_when: False + failed_when: "_netbox_git_contains_trace_paths.rc not in [0, 1]" -- name: Check existence of commit e165dca, introducing mkdocs command during update - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^7058d6ca5ae2901383874bcea5fedad31e165dca' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_mkdocs - changed_when: False - failed_when: "_netbox_git_contains_mkdocs.rc not in [0, 1]" + - name: Check existence of commit e165dca, introducing mkdocs command during update + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^7058d6ca5ae2901383874bcea5fedad31e165dca' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_mkdocs + changed_when: False + failed_when: "_netbox_git_contains_mkdocs.rc not in [0, 1]" -- name: Check existence of commit d87ec82, introducing nightly housekeeping command - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^d87ec82fe34d92a84ee6f2a97ba0a87a53eed015' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_housekeeping - changed_when: False - failed_when: "_netbox_git_contains_housekeeping.rc not in [0, 1]" + - name: Check existence of commit d87ec82, introducing nightly housekeeping command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^d87ec82fe34d92a84ee6f2a97ba0a87a53eed015' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_housekeeping + changed_when: False + failed_when: "_netbox_git_contains_housekeeping.rc not in [0, 1]" -- name: Check existence of commit 028c876, removing the invalidate command - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^028c876bcafbaede2731f191512bbebe3f1b6a9e' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_invalidate_removed - changed_when: False - failed_when: "_netbox_git_contains_invalidate_removed.rc not in [0, 1]" + - name: Check existence of commit 028c876, removing the invalidate command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^028c876bcafbaede2731f191512bbebe3f1b6a9e' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_invalidate_removed + changed_when: False + failed_when: "_netbox_git_contains_invalidate_removed.rc not in [0, 1]" -- name: Check existence of commit b172ae6, adding the clearcache command - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^b172ae65d24f6dc161c4b609477a4547bb62a50b' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_add_clearcache - changed_when: False - failed_when: "_netbox_git_contains_add_clearcache.rc not in [0, 1]" + - name: Check existence of commit b172ae6, adding the clearcache command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^b172ae65d24f6dc161c4b609477a4547bb62a50b' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_add_clearcache + changed_when: False + failed_when: "_netbox_git_contains_add_clearcache.rc not in [0, 1]" + + become: true + become_user: "{{ netbox_user }}" - name: Archive and extract snapshot of git repository shell: 'set -o pipefail; git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"' From a278b093dabe345a7de92f2de8538dd65a2cd41a Mon Sep 17 00:00:00 2001 From: David Mehren Date: Wed, 10 Jan 2024 16:01:41 +0100 Subject: [PATCH 07/10] Compatibility with Netbox 3.7 https://github.com/netbox-community/netbox/commit/2d1f88272497ca72d2e1eca8e291c04538c6810e removed the 'clearcache' command --- tasks/deploy_netbox.yml | 8 +++++--- tasks/install_via_git.yml | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 9a303af..874fbab 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -204,7 +204,7 @@ app_path: "{{ netbox_current_path }}/netbox" virtualenv: "{{ netbox_virtualenv_path }}" - - name: Clear cached data in NetBox + - name: Clear cached data in NetBox < 3 django_manage: command: "invalidate all" app_path: "{{ netbox_current_path }}/netbox" @@ -213,14 +213,16 @@ - netbox_stable and netbox_stable_version is version('3.0.0', '<') or netbox_git and _netbox_git_contains_invalidate_removed.rc != 0 - - name: Clear cached data in NetBox 3.2.3+ + - name: Clear cached data in NetBox 3.2.3 to 3.6 django_manage: command: "clearcache" app_path: "{{ netbox_current_path }}/netbox" virtualenv: "{{ netbox_virtualenv_path }}" when: - netbox_stable and netbox_stable_version is version('3.2.2', '>') - or netbox_git and _netbox_git_contains_add_clearcache.rc == 0 + and netbox_stable_version is version('3.7.0', '<') + or netbox_git and _netbox_git_contains_add_clearcache.rc == 0 + and _netbox_git_contains_remove_clearcache != 0 become: true become_user: "{{ netbox_user }}" diff --git a/tasks/install_via_git.yml b/tasks/install_via_git.yml index 7e3afda..646d4aa 100644 --- a/tasks/install_via_git.yml +++ b/tasks/install_via_git.yml @@ -87,6 +87,15 @@ changed_when: False failed_when: "_netbox_git_contains_add_clearcache.rc not in [0, 1]" +- name: Check existence of commit 2d1f882, removing the clearcache command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^2d1f88272497ca72d2e1eca8e291c04538c6810e' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_remove_clearcache + changed_when: False + failed_when: "_netbox_git_contains_remove_clearcache.rc not in [0, 1]" + - name: Archive and extract snapshot of git repository shell: 'set -o pipefail; git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"' args: From af712839c84e484e70aa5e7d854b8fcbb5aa2e06 Mon Sep 17 00:00:00 2001 From: "Simon Leinen (SWITCH)" Date: Tue, 30 Jan 2024 17:03:15 +0100 Subject: [PATCH 08/10] Fix check for clearcache removal in the Git case --- tasks/deploy_netbox.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 874fbab..3c95501 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -221,8 +221,8 @@ when: - netbox_stable and netbox_stable_version is version('3.2.2', '>') and netbox_stable_version is version('3.7.0', '<') - or netbox_git and _netbox_git_contains_add_clearcache.rc == 0 - and _netbox_git_contains_remove_clearcache != 0 + or netbox_git and ( _netbox_git_contains_add_clearcache.rc == 0 + and _netbox_git_contains_remove_clearcache.rc != 0 ) become: true become_user: "{{ netbox_user }}" From e00faa5c468981f2c4fdb79ce314beb12adbfe10 Mon Sep 17 00:00:00 2001 From: "Simon Leinen (SWITCH)" Date: Tue, 30 Jan 2024 17:03:34 +0100 Subject: [PATCH 09/10] Run check for clearcache removal commit under "become" ...like the other checks. --- tasks/install_via_git.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tasks/install_via_git.yml b/tasks/install_via_git.yml index 91cc682..a1a0615 100644 --- a/tasks/install_via_git.yml +++ b/tasks/install_via_git.yml @@ -89,18 +89,18 @@ changed_when: False failed_when: "_netbox_git_contains_add_clearcache.rc not in [0, 1]" + - name: Check existence of commit 2d1f882, removing the clearcache command + shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^2d1f88272497ca72d2e1eca8e291c04538c6810e' + args: + chdir: "{{ netbox_git_repo_path }}" + executable: /bin/bash + register: _netbox_git_contains_remove_clearcache + changed_when: False + failed_when: "_netbox_git_contains_remove_clearcache.rc not in [0, 1]" + become: true become_user: "{{ netbox_user }}" -- name: Check existence of commit 2d1f882, removing the clearcache command - shell: 'set -o pipefail; git log --format=%H "{{ netbox_git_version }}" | grep ^2d1f88272497ca72d2e1eca8e291c04538c6810e' - args: - chdir: "{{ netbox_git_repo_path }}" - executable: /bin/bash - register: _netbox_git_contains_remove_clearcache - changed_when: False - failed_when: "_netbox_git_contains_remove_clearcache.rc not in [0, 1]" - - name: Archive and extract snapshot of git repository shell: 'set -o pipefail; git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"' args: From 904ccc3d648084b666f98a55b8adc5e7e78a0bb7 Mon Sep 17 00:00:00 2001 From: Musee Ullah Date: Fri, 23 Feb 2024 19:25:16 +0900 Subject: [PATCH 10/10] Clarify community.postgresql usage in docs --- README.adoc | 23 ++++++++++++++++++----- tasks/main.yml | 4 ++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.adoc b/README.adoc index 2351505..d25a6b0 100644 --- a/README.adoc +++ b/README.adoc @@ -39,6 +39,7 @@ Provided you have Ansible installed and are using defaults: [source,bash,subs="attributes"] ---- ansible-galaxy install geerlingguy.postgresql davidwittman.redis {role} +ansible-galaxy collection install community.postgresql ansible-playbook -i your.server.fqdn, ~/.ansible/roles/{role}/examples/playbook_single_host_deploy.yml -K ---- @@ -50,6 +51,7 @@ You can also use Vagrant, if you prefer, to bring up NetBox at `localhost:8080`: [source,bash,subs="attributes"] ---- ansible-galaxy install geerlingguy.postgresql davidwittman.redis {role} +ansible-galaxy collection install community.postgresql cd ~/.ansible/roles/{role}/ vagrant up ---- @@ -70,12 +72,23 @@ endif::[] === PostgreSQL -This role does not setup a PostgreSQL server (but will create a database if -needed), so you'll need to setup a PostgreSQL server and create a database user -separate from this role. Take a look at the _Example Playbook_ section. +This role does not setup a PostgreSQL server (but will create a database if needed), so you'll need to setup a PostgreSQL server and create a database user separate from this role. +Take a look at the _Example Playbook_ section. -WARNING: NetBox v2.2.0+ require PostgreSQL 9.4 at the minimum, which may not be -available in your distribution's repos. You may want to use a role for this. +In addition, for Ansible 2.10+, you may need to install the `community.postgresql` collection. +It is recommended to specify this in your playbook's `requirements.yml` file. +For example: + +[source,yaml] +---- +--- +collections: + - name: community.postgresql + version: 3.4.0 +---- + +WARNING: NetBox v2.2.0+ require PostgreSQL 9.4 at the minimum, which may not be available in your distribution's repos. +You may want to use a role for this. === Redis diff --git a/tasks/main.yml b/tasks/main.yml index c4605a3..9f52ca3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -42,7 +42,7 @@ home: "{{ netbox_home }}" - name: Ensure Postgres database exists (via socket) - postgresql_db: + community.postgresql.postgresql_db: name: "{{ netbox_database }}" login_user: "{{ netbox_database_user }}" login_unix_socket: "{{ netbox_database_socket }}" @@ -54,7 +54,7 @@ - netbox_database_host is not defined - name: Ensure Postgres database exists (via TCP) - postgresql_db: + community.postgresql.postgresql_db: name: "{{ netbox_database }}" login_host: "{{ netbox_database_host }}" port: "{{ netbox_database_port }}"