diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 4854018..745d968 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -86,72 +86,72 @@ - restart netbox.service - restart netbox-rqworker.service -- name: Generate NetBox configuration file - template: - src: templates/configuration.py.j2 - dest: "{{ netbox_shared_path }}/configuration.py" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - mode: 0640 - validate: "{{ netbox_virtualenv_path }}/bin/python -c \"import py_compile,os; f=r'%s';\ - c='/tmp/' + os.path.basename(os.path.dirname(f)) + '-' + os.path.basename(f) + 'c';\ - py_compile.compile(f, c); os.remove(c)\"" - notify: - - reload netbox.service - - restart netbox-rqworker.service +- name: NetBox Configuration + block: + # configuration.py + - name: Generate NetBox configuration file + ansible.builtin.template: + src: templates/configuration.py.j2 + dest: "{{ netbox_shared_path }}/configuration.py" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + mode: 0640 + validate: "{{ netbox_virtualenv_path }}/bin/python -c \"import py_compile,os; f=r'%s';\ + c='/tmp/' + os.path.basename(os.path.dirname(f)) + '-' + os.path.basename(f) + 'c';\ + py_compile.compile(f, c); os.remove(c)\"" + notify: + - restart netbox-rqworker.service -- name: Generate LDAP configuration for NetBox if enabled - template: - src: "{{ netbox_ldap_config_template }}" - dest: "{{ netbox_shared_path }}/ldap_config.py" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - mode: 0640 - validate: "{{ netbox_virtualenv_path }}/bin/python -c \"import py_compile,os; f=r'%s';\ - c='/tmp/' + os.path.basename(os.path.dirname(f)) + '-' + os.path.basename(f) + 'c';\ - py_compile.compile(f, c); os.remove(c)\"" - notify: - - reload netbox.service - when: - - netbox_ldap_enabled + - name: Symlink NetBox configuration file into the active NetBox release + ansible.builtin.file: + src: "{{ netbox_shared_path }}/configuration.py" + dest: "{{ netbox_config_path }}/configuration.py" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + state: link -- name: Symlink NetBox configuration file into the active NetBox release - file: - src: "{{ netbox_shared_path }}/configuration.py" - dest: "{{ netbox_config_path }}/configuration.py" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - state: link + # ldap_config.py + - name: Generate LDAP configuration for NetBox if enabled + ansible.builtin.template: + src: "{{ netbox_ldap_config_template }}" + dest: "{{ netbox_shared_path }}/ldap_config.py" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + mode: 0640 + validate: "{{ netbox_virtualenv_path }}/bin/python -c \"import py_compile,os; f=r'%s';\ + c='/tmp/' + os.path.basename(os.path.dirname(f)) + '-' + os.path.basename(f) + 'c';\ + py_compile.compile(f, c); os.remove(c)\"" + when: + - netbox_ldap_enabled -- name: Symlink/Remove NetBox LDAP configuration file into/from the active NetBox release - file: - src: "{{ netbox_shared_path + '/ldap_config.py' if netbox_ldap_enabled else omit }}" - dest: "{{ netbox_config_path }}/ldap_config.py" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - state: "{{ 'link' if netbox_ldap_enabled else 'absent' }}" - notify: - - reload netbox.service + - name: Symlink/Remove NetBox LDAP configuration file into/from the active NetBox release + ansible.builtin.file: + src: "{{ netbox_shared_path + '/ldap_config.py' if netbox_ldap_enabled else omit }}" + dest: "{{ netbox_config_path }}/ldap_config.py" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + mode: 0640 + state: "{{ 'link' if netbox_ldap_enabled else 'absent' }}" -# local_settings.py -- name: Copy NetBox local_settings.py into shared (ignore if it doesn't exist) - ansible.builtin.copy: - src: "{{ netbox_local_settings_file }}" - dest: "{{ netbox_shared_path }}/local_settings.py" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - when: - - netbox_local_settings_file is defined - notify: - - reload netbox.service + # local_settings.py + - name: Copy NetBox local_settings.py into shared (ignore if it doesn't exist) + ansible.builtin.copy: + src: "{{ netbox_local_settings_file }}" + dest: "{{ netbox_shared_path }}/local_settings.py" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + mode: 0640 + when: + - netbox_local_settings_file is defined -- name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release - ansible.builtin.file: - src: "{{ netbox_shared_path }}/local_settings.py" - dest: "{{ netbox_config_path }}/local_settings.py" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - state: "{{ 'link' if netbox_local_settings_file is defined else 'absent' }}" + - name: Symlink/Remove NetBox local_settings.py file into/from the active NetBox release + ansible.builtin.file: + src: "{{ netbox_shared_path }}/local_settings.py" + dest: "{{ netbox_config_path }}/local_settings.py" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + mode: 0640 + state: "{{ 'link' if netbox_local_settings_file is defined else 'absent' }}" notify: - reload netbox.service