Hi,
I’m creating a super user for my django application through ansible. Script is below.
django_manage: command=“createsuperuser --noinput --username=admin --email=anoop.kolari@tarams.com” app_path={{ django_dir }} settings={{settings_path}}
Its creating the super user with some random password. Please let me know the following at the earliest.
- Is it possible to set password with the command?
- Whats the default password its setting when executing that command?
This is really more of a Django issue than an Ansible one. It's most
likely creating the user with an unusable password ("*").
There isn't a way with the built-in createsuperuser command to set a
password. You can find one approach that addresses this problem at
http://source.mihelac.org/2009/10/23/django-avoiding-typing-password-for-superuser/
.
Thanks Chris.
Instead of the solution you have suggested, I’m tried to create a custom django manage command. But when i invoked this from ansible through django_manage, its throws an error like the one below.
fatal: [djangoskeleton-local.com] => failed to parse: SUDO-SUCCESS-wzpnssbmxbwqvxmfgljczjecbynjytor
Traceback (most recent call last):
File “/home/vagrant/.ansible/tmp/ansible-tmp-1449209268.07-207237531077051/django_manage”, line 1627, in
main()
File “/home/vagrant/.ansible/tmp/ansible-tmp-1449209268.07-207237531077051/django_manage”, line 228, in main
if value and param not in command_allowed_param_map[command]:
KeyError: ‘change_django_admin_password --username=admin --password=tarams123’
FATAL: all hosts have already failed – aborting
This command works fine when I tried from python manage.py shell.
Could you please suggest.
Could you paste the task you're using that gives this error?
Hi Chris,
I have created a custom django management command to set admin password called ‘change_django_admin_password’ and calling this through ansible as below;
- name: “Run django manage commands for the apps.”
django_manage:
command=“{{item.cmd}}”
app_path=“{{DJANGO_PROJECT.guest.root}}/{{DJANGO_PROJECT.guest.name}}”
apps=“{{item.apps}}”
settings=“{{DJANGO_PROJECT.guest.name}}.settings”
with_items:
- {cmd: “change_django_admin_password --username={{DJANGO_PROJECT.admin.username}} --password={{DJANGO_PROJECT.admin.password}}”, apps: “”}
This giving me the error mentioned earlier.