Skip to content

Instantly share code, notes, and snippets.

@kelvinn
Created June 10, 2014 06:39
Show Gist options
  • Save kelvinn/a34581ea18894e22b3a8 to your computer and use it in GitHub Desktop.
Save kelvinn/a34581ea18894e22b3a8 to your computer and use it in GitHub Desktop.
Example of creating Django superuser (with password) in dev environment using SaltStack
import os
import sys
# First, add the project to PATH. Adjust as needed.
PWD = os.path.dirname(os.path.abspath(__file__))
PROJECT_PATH = os.path.abspath(os.path.join(PWD, '../../../../'))
sys.path.append(PROJECT_PATH)
# Second, configure this script to use Django
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
try:
django.setup()
except AttributeError:
print django.VERSION
from django.contrib.auth.management.commands import changepassword
from django.core import management
# Create the super user and sets his password.
management.call_command('createsuperuser', interactive=False, username="admin", email="[email protected]")
command = changepassword.Command()
command._get_pass = lambda *args: 'password'
command.execute("admin")
# If you have multiple environments in SaltStack you can states based
# on which env they are in. This is in my dev env.
# You will need to modify these two files accordingly.
# This could be a script.wait, but
create_superuser:
cmd.wait:
- name: python salt/roots/dev/extra/create_dev_superuser.py
- cwd: {{ pillar.project_dir }}
- output_loglevel: quiet
- watch:
- postgres_database: state_to_create_db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment