# Ansible createsuperuser with django\_manage module.

**URL:** <https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925>\
**Category:** Ansible Project\
**Created:** [December 3, 2015, 5:05am UTC](https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925 "2015-12-03T05:05:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anoop.kolari](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anoop.kolari](https://forum.ansible.com/u/anoop.kolari)\
**Post date:** [December 3, 2015, 5:05am UTC](https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925/1 "2015-12-03T05:05:20Z")

</div>

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](mailto: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.

1. Is it possible to set password with the command?
2. Whats the default password its setting when executing that command?

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [December 3, 2015, 4:00pm UTC](https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925/2 "2015-12-03T16:00:16Z")

</div>

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/](http://source.mihelac.org/2009/10/23/django-avoiding-typing-password-for-superuser/)  
.

---

<div class="post-metadata">

**Author:** ![anoop.kolari](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anoop.kolari](https://forum.ansible.com/u/anoop.kolari)\
**Post date:** [December 4, 2015, 6:09am UTC](https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925/3 "2015-12-04T06:09:52Z")

</div>

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](http://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.

---

<div class="post-metadata">

**Author:** ![Chris\_Church1](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@Chris\_Church1](https://forum.ansible.com/u/Chris_Church1)\
**Post date:** [December 7, 2015, 1:36pm UTC](https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925/4 "2015-12-07T13:36:19Z")

</div>

Could you paste the task you're using that gives this error?

---

<div class="post-metadata">

**Author:** ![anoop.kolari](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anoop.kolari](https://forum.ansible.com/u/anoop.kolari)\
**Post date:** [December 7, 2015, 5:18pm UTC](https://forum.ansible.com/t/ansible-createsuperuser-with-django-manage-module/19925/5 "2015-12-07T17:18:35Z")

</div>

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.
