Ansible createsuperuser with django_manage module.

826 views
Skip to first unread message

anoop....@tarams.com

unread,
Dec 3, 2015, 12:05:52 AM12/3/15
to Ansible Project

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.


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


 =============================
DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Further, this e-mail may contain viruses and all reasonable precaution to minimize the risk arising there from is taken by Tarams. Tarams is not liable for any damage sustained by you as a result of any virus in this e-mail. All applicable virus checks should be carried out by you before opening this e-mail or any attachment thereto.
Thank you - Tarams Software Technologies Pvt.Ltd.
=============================

Chris Church

unread,
Dec 3, 2015, 11:00:44 AM12/3/15
to ansible...@googlegroups.com
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/.


On Thu, Dec 3, 2015 at 12:05 AM, <anoop....@tarams.com> wrote:

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....@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?


 =============================
DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Further, this e-mail may contain viruses and all reasonable precaution to minimize the risk arising there from is taken by Tarams. Tarams is not liable for any damage sustained by you as a result of any virus in this e-mail. All applicable virus checks should be carried out by you before opening this e-mail or any attachment thereto.
Thank you - Tarams Software Technologies Pvt.Ltd.
=============================

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bcbd0d27-f686-4ff2-a88d-5c1cbd8aaef6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

anoop....@tarams.com

unread,
Dec 4, 2015, 1:09:53 AM12/4/15
to Ansible Project
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 <module>
    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. 

Chris Church

unread,
Dec 7, 2015, 8:36:57 AM12/7/15
to ansible...@googlegroups.com
Could you paste the task you're using that gives this error?  

On Fri, Dec 4, 2015 at 1:09 AM, <anoop....@tarams.com> wrote:
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 <module>
    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. 

On Thursday, December 3, 2015 at 10:35:52 AM UTC+5:30, anoop....@tarams.com wrote:

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....@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?


 =============================
DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Further, this e-mail may contain viruses and all reasonable precaution to minimize the risk arising there from is taken by Tarams. Tarams is not liable for any damage sustained by you as a result of any virus in this e-mail. All applicable virus checks should be carried out by you before opening this e-mail or any attachment thereto.
Thank you - Tarams Software Technologies Pvt.Ltd.
=============================

 =============================
DISCLAIMER: The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful. Please immediately contact the sender if you have received this message in error. Further, this e-mail may contain viruses and all reasonable precaution to minimize the risk arising there from is taken by Tarams. Tarams is not liable for any damage sustained by you as a result of any virus in this e-mail. All applicable virus checks should be carried out by you before opening this e-mail or any attachment thereto.
Thank you - Tarams Software Technologies Pvt.Ltd.
=============================

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

anoop....@tarams.com

unread,
Dec 7, 2015, 12:18:35 PM12/7/15
to Ansible Project
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.
 

On Thursday, December 3, 2015 at 10:35:52 AM UTC+5:30, anoop....@tarams.com wrote:
Reply all
Reply to author
Forward
0 new messages