django_manage module detailed explaination

647 views
Skip to first unread message

Eric sharma

unread,
Dec 23, 2014, 6:13:37 AM12/23/14
to ansible...@googlegroups.com
The module provide here
http://docs.ansible.com/django_manage_module.html
needs to have some more example for manage.py command.

example: createsuperuser. How can we create superuser with a specific username and password? is there any way to pass this information in this module


- name: Django Create Superuser
  django_manage: command=createsuperuser
                 app_path
={{app_path}}
                 settings
={{django_settings}}
  tags
:
   
- django

and how do we use latest django'(1.7)'s makemigration command where we have to give app name (I mean  
 python manage.py makemigration app1
)

for same environment/path settings collectstatic command works perfectly

- name: Django Collectstatic
  django_manage
: command=collectstatic
                 app_path
={{app_path}}
                 settings
={{django_settings}}


Could somebody please provide example of these

Thanks

Chris Church

unread,
Dec 25, 2014, 12:25:55 AM12/25/14
to ansible...@googlegroups.com
The createsuperuser command doesn't support a command line option to set a password; you can only set username and email when running with the --noinput flag.  There are hackish workarounds for creating an initial superuser with password (http://source.mihelac.org/2009/10/23/django-avoiding-typing-password-for-superuser/), but these wouldn't use the django_manage module.  Your other option would be writing your own custom management command for creating superusers.

For running django management commands not specifically listed in the docs, or to use custom command options, you can specify your command and options as a single string, e.g.:

- django_manage: command="makemigrations --noinput app1" app_path={{app_path}} settings={{django_settings}}



--
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/80ad9495-a9d4-43a1-a63b-10f08e465369%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric sharma

unread,
Dec 25, 2014, 10:59:38 AM12/25/14
to ansible...@googlegroups.com
Thanks Chris

Your solution for makemigrations command working perfect but I didn't find similar thing in docs. have I missed something?
I've two more small queries.
1) how do I pass multiple app name in makemigrations command which is in a variable (I mean using ansible's with_items)

- name: Django makemigrations
  django_manage
: command="makemigrations --noinput app1" app_path={{app_path}} settings={{django_settings}}

  with_items
:
       
-  app1
       
-  app2
       
-  app3

2) how do I pass username and password in createsuperuser command?
I run this task but it didn't work?

- django_manage: command="createsuperuser --noinput myuser mye...@xyz.com mypassword" app_path={{app_path}} settings={{django_settings}}


Thanks again for --input thing :)






Chris Church

unread,
Dec 26, 2014, 1:33:33 AM12/26/14
to ansible...@googlegroups.com
To use with_items, replace app1 in your command with the variable {{item}}:

- django_manage: >
    command="makemigrations --noinput {{item}}"
    app_path={{app_path}}
    settings={{django_settings}}
  with_items:
    - app1
    - app2
    - app3


The createsuperuser command doesn't support setting a password from the command line.  I've found a simple third-party app (https://github.com/ActiveState/django-stackato) to add a management command for changing a user's password, so after installing it you could run something like:

- django_manage: >
    command="createsuperuser --noinput --username=myuser --email=mye...@xyz.com"
    app_path={{app_path}}
    settings={{django_settings}}
- django_manage: >
    command="changepassword2 myuser mypassword"
    app_path={{app_path}}
    settings={{django_settings}}

The django_manage documentation does indicate that "Other commands can be entered, but will fail if they're unknown to Django.", but it doesn't give an example of running one that's not in the list of built-in commands.  I've submitted a fix (https://github.com/ansible/ansible-modules-core/pull/574).



--
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.
Reply all
Reply to author
Forward
0 new messages