Skip to content

Commit af80420

Browse files
committed
Merge branch 'release/0.6.0'
2 parents d50af0c + db01048 commit af80420

File tree

13 files changed

+56
-38
lines changed

13 files changed

+56
-38
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ ansible-playbook -i your.server.fqdn, ~/.ansible/roles/lae.netbox/examples/playb
3131
This will deploy NetBox and PostgreSQL on `your.server.fqdn`; once complete it
3232
should be accessible on port 80. Modify if needed. Read below for more insight.
3333

34+
You can also use Vagrant, if you prefer, to bring up NetBox at `localhost:8080`:
35+
36+
```
37+
ansible-galaxy install geerlingguy.postgresql lae.netbox
38+
cd ~/.ansible/roles/lae.netbox/
39+
vagrant up
40+
```
41+
3442
Prerequisites
3543
-------------
3644

Vagrantfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Vagrant.configure("2") do |config|
2+
config.vm.box = "generic/debian9"
3+
config.vm.network "forwarded_port", guest: 80, host: 8080, auto_correct: true
4+
5+
config.vm.provision "ansible" do |ansible|
6+
ansible.playbook = "examples/playbook_single_host_deploy.yml"
7+
end
8+
end

examples/playbook_single_host_deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
netbox_config:
1212
ALLOWED_HOSTS:
1313
- "{{ inventory_hostname }}"
14+
# The following should not be used in production, probably.
15+
# This playbook gets used by Vagrant where we don't know the actual hostname.
16+
- "*"
1417
MEDIA_ROOT: "{{ netbox_shared_path }}/media"
1518
REPORTS_ROOT: "{{ netbox_shared_path }}/reports"
1619
netbox_database_socket: "{{ postgresql_unix_socket_directories[0] }}"

meta/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
galaxy_info:
2-
role_name: netbox
32
author: Musee Ullah
43
description: Installs and configures NetBox, a DCIM suite, in a production setting.
54
license: MIT
6-
min_ansible_version: 2.4
5+
min_ansible_version: 2.5
76
platforms:
87
- name: Ubuntu
98
versions:

tasks/deploy_netbox.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
state: directory
66
owner: "{{ netbox_user }}"
77
group: "{{ netbox_group }}"
8-
with_items:
8+
loop:
99
- "{{ netbox_releases_path }}"
1010
- "{{ netbox_shared_path }}"
1111
- "{{ netbox_shared_path }}/media/image-attachments"
@@ -101,8 +101,8 @@
101101

102102
- name: Create a super user for NetBox
103103
shell: "printf '{{ netbox_superuser_script }}' | {{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py shell"
104-
register: __netbox_superuser_result
105-
changed_when: "'changed' in __netbox_superuser_result.stdout"
104+
register: _netbox_superuser_result
105+
changed_when: "'changed' in _netbox_superuser_result.stdout"
106106
when:
107107
- not netbox_ldap_enabled
108108

tasks/generate_secret_key.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Generate a SECRET_KEY for NetBox if unspecified
3-
shell: "{{ netbox_current_path }}/netbox/generate_secret_key.py | tr -d $'\n' > {{ netbox_shared_path }}/generated_secret_key"
3+
shell: "{{ netbox_python_binary }} {{ netbox_current_path }}/netbox/generate_secret_key.py | tr -d $'\n' > {{ netbox_shared_path }}/generated_secret_key"
44
args:
55
creates: "{{ netbox_shared_path }}/generated_secret_key"
66
become: True
@@ -9,8 +9,8 @@
99
- name: Load saved SECRET_KEY
1010
slurp:
1111
src: "{{ netbox_shared_path }}/generated_secret_key"
12-
register: __netbox_secret_key_file
12+
register: _netbox_secret_key_file
1313

1414
- name: Set netbox_config.SECRET_KEY to generated SECRET_KEY
1515
set_fact:
16-
netbox_config: "{{ netbox_config | combine({'SECRET_KEY': __netbox_secret_key_file['content'] | b64decode}) }}"
16+
netbox_config: "{{ netbox_config | combine({'SECRET_KEY': _netbox_secret_key_file['content'] | b64decode}) }}"

tasks/install_packages_apt.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
repo: "{{ item }}"
55
state: present
66
update_cache: yes
7-
with_items:
7+
loop:
88
- "deb http://in.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }} main universe"
99
- "deb http://in.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-updates main universe"
1010
- "deb http://in.archive.ubuntu.com/ubuntu/ {{ ansible_distribution_release }}-backports main universe"
@@ -13,13 +13,14 @@
1313

1414
- name: Install required packages for selected NetBox configuration
1515
apt:
16-
name: "{{ item }}"
17-
state: latest
16+
name: "{{ _netbox_apt_packages | flatten }}"
17+
state: present
1818
cache_valid_time: 3600
1919
update_cache: yes
20-
with_items:
21-
- "{{ netbox_python_packages }}"
22-
- "{{ netbox_packages }}"
23-
- "{{ netbox_ldap_packages if netbox_ldap_enabled else [] }}"
24-
- "{{ 'git' if netbox_git else [] }}"
25-
- "{{ 'acl' if ('SUDO_USER' in ansible_env and ansible_env.SUDO_USER != 'root') else [] }}"
20+
vars:
21+
_netbox_apt_packages:
22+
- "{{ netbox_python_packages }}"
23+
- "{{ netbox_packages }}"
24+
- "{{ netbox_ldap_packages if netbox_ldap_enabled else [] }}"
25+
- "{{ 'git' if netbox_git else [] }}"
26+
- "{{ 'acl' if ('SUDO_USER' in ansible_env and ansible_env.SUDO_USER != 'root') else [] }}"

tasks/install_packages_yum.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
- name: Install required packages for selected NetBox configuration
88
yum:
9-
name: "{{ item }}"
9+
name: "{{ _netbox_yum_packages | flatten }}"
1010
state: latest
1111
update_cache: yes
12-
with_items:
13-
- "{{ netbox_python_packages }}"
14-
- "{{ netbox_packages }}"
15-
- "{{ netbox_ldap_packages if netbox_ldap_enabled else [] }}"
16-
- "{{ 'git' if netbox_git else [] }}"
17-
- "{{ 'acl' if ('SUDO_USER' in ansible_env and ansible_env.SUDO_USER != 'root') else [] }}"
12+
vars:
13+
_netbox_yum_packages:
14+
- "{{ netbox_python_packages }}"
15+
- "{{ netbox_packages }}"
16+
- "{{ netbox_ldap_packages if netbox_ldap_enabled else [] }}"
17+
- "{{ 'git' if netbox_git else [] }}"
18+
- "{{ 'acl' if ('SUDO_USER' in ansible_env and ansible_env.SUDO_USER != 'root') else [] }}"

tasks/install_via_git.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
repo: "{{ netbox_git_uri }}"
55
dest: "{{ netbox_git_repo_path }}"
66
version: "{{ netbox_git_version }}"
7-
register: __netbox_git_repo
7+
register: _netbox_git_repo
88
become: True
99
become_user: "{{ netbox_user }}"
1010

@@ -19,9 +19,9 @@
1919
shell: 'git log --format=%H "{{ netbox_git_version }}" | grep ^1fb67b791f1a91c624dae4a1cd256e4cf3ddbb77'
2020
args:
2121
chdir: "{{ netbox_git_repo_path }}"
22-
register: __netbox_git_contains_issue_2239_fix
22+
register: _netbox_git_contains_issue_2239_fix
2323
changed_when: False
24-
failed_when: "__netbox_git_contains_issue_2239_fix.rc not in [0, 1]"
24+
failed_when: "_netbox_git_contains_issue_2239_fix.rc not in [0, 1]"
2525

2626
- name: Archive and extract snapshot of git repository
2727
shell: 'git archive "{{ netbox_git_version }}" | tar -x -C "{{ netbox_git_deploy_path }}"'
@@ -30,7 +30,7 @@
3030
notify:
3131
- reload netbox.service
3232
when:
33-
- __netbox_git_repo is changed
33+
- _netbox_git_repo is changed
3434
become: True
3535
become_user: "{{ netbox_user }}"
3636

tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@
8787
name: "{{ item }}"
8888
state: started
8989
enabled: yes
90-
with_items:
90+
loop:
9191
- netbox.socket
9292
- netbox.service

0 commit comments

Comments
 (0)