Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add task for creating an API token for the superuser #128

Merged
merged 13 commits into from
May 22, 2021
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ netbox_install_epel: true
netbox_superuser_username: admin
# netbox_superuser_password: changeme
netbox_superuser_email: admin@localhost
netbox_superuser_token_enabled: false

netbox_database: netbox
netbox_database_user: netbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
hosts: all
become: true
vars:
redis_version: 6.2.1
netbox_stable_version: 2.10.8
netbox_stable: true
netbox_socket: "0.0.0.0:80"
netbox_superuser_password: netbox
netbox_superuser_token_enabled: true
netbox_config:
ALLOWED_HOSTS:
- "{{ inventory_hostname }}"
Expand Down
13 changes: 9 additions & 4 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
dependency:
name: galaxy
driver:
name: vagrant
name: docker
provider:
name: virtualbox
name: centos8
lae marked this conversation as resolved.
Show resolved Hide resolved
lint: |
set -e
yamllint .
ansible-lint
flake8
platforms:
- name: debian-9
box: generic/debian9
- name: centos8
image: geerlingguy/docker-centos8-ansible:latest
command: /sbin/init
privileged: True
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
pre_build_image: true
provisioner:
name: ansible
log: true
Expand Down
9 changes: 9 additions & 0 deletions tasks/deploy_netbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@
when:
- not netbox_ldap_enabled

- name: Create a super user token for NetBox
shell: "printf '{{ netbox_superuser_token }}' |\
{{ netbox_virtualenv_path }}/bin/python {{ netbox_current_path }}/netbox/manage.py shell"
register: _netbox_superuser_token
changed_when: "'changed' in _netbox_superuser_token.stdout"
when:
- not netbox_ldap_enabled
- netbox_superuser_token_enabled

- name: Generate static assets for NetBox
django_manage:
command: collectstatic
Expand Down
8 changes: 8 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ netbox_superuser_script: |
user.set_password(password)
user.save()
print("changed")

netbox_superuser_token: |
from users.models import Token
from django.contrib.auth.models import User
user = User.objects.get(username="{{ netbox_superuser_username }}")
token = Token.objects.create(user=user)
print("api-token: " + token.key)
print("changed")
florianow marked this conversation as resolved.
Show resolved Hide resolved