Skip to content

Commit

Permalink
move config file deployment tasks into a single block + lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lae committed Nov 29, 2024
1 parent deff247 commit 3ba1e68
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions tasks/deploy_netbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3ba1e68

Please sign in to comment.