community.general.django_manage module – Manages a Django application


This module is part of the community.general collection (version 6.1.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this module, see Requirements for details.

To use it in a playbook, specify: community.general.django_manage.


  • Manages a Django application using the application frontend to django-admin. With the virtualenv parameter, all management commands will be executed by the given virtualenv installation.


The below requirements are needed on the host that executes this module.

  • virtualenv

  • django






added in community.general 5.8.0

When a virtualenv is set but the virtual environment does not exist, the current behavior is to create a new virtual environment. That behavior is deprecated and if that case happens it will generate a deprecation warning. Set this flag to true to suppress the deprecation warning.

Please note that you will receive no further warning about this being removed until the module will start failing in such cases from community.general 9.0.0 on.


  • false

  • true



A list of space-delimited apps to target. Used by the test command.



The name of the table used for database-backed caching. Used by the createcachetable command.



Clear the existing files before trying to copy or link the original file.

Used only with the collectstatic command. The --noinput argument will be added automatically.


  • false ← (default)

  • true


string / required

The name of the Django management command to run. The commands listed below are built in this module and have some basic parameter validation.

cleanup - clean up old data from the database (deprecated in Django 1.5). This parameter will be removed in community.general 9.0.0. Use clearsessions instead.

collectstatic - Collects the static files into STATIC_ROOT.

createcachetable - Creates the cache tables for use with the database cache backend.

flush - Removes all data from the database.

loaddata - Searches for and loads the contents of the named fixtures into the database.

migrate - Synchronizes the database state with models and migrations.

syncdb - Synchronizes the database state with models and migrations (deprecated in Django 1.7). This parameter will be removed in community.general 9.0.0. Use migrate instead.

test - Runs tests for all installed apps.

validate - Validates all installed models (deprecated in Django 1.7). This parameter will be removed in community.general 9.0.0. Use check instead.

Other commands can be entered, but will fail if they are unknown to Django. Other commands that may prompt for user input should be run with the --noinput flag.



The database to target. Used by the createcachetable, flush, loaddata, syncdb, and migrate commands.


aliases: fail_fast


Fail the command immediately if a test fails. Used by the test command.


  • false ← (default)

  • true



A space-delimited list of fixture file names to load in the database. Required by the loaddata command.


Will create links to the files instead of copying them, you can only use this parameter with collectstatic command.


  • false

  • true



Will run out-of-order or missing migrations as they are not rollback migrations, you can only use this parameter with migrate command.


  • false

  • true


aliases: app_path, chdir

path / required

The path to the root of the Django application where lives.


aliases: python_path


A directory to add to the Python path. Typically used to include the settings module if it is located external to the application directory.

This would be equivalent to adding pythonpath‘s value to the PYTHONPATH environment variable.



The Python path to the application’s settings module, such as myapp.settings.



Will skip over out-of-order missing migrations, you can only use this parameter with migrate command.


  • false

  • true


aliases: test_runner


Controls the test runner class that is used to execute tests.

This parameter is passed as-is to


aliases: virtual_env


An optional path to a virtualenv installation to use while running the manage application.



  • ATTENTION - DEPRECATION: Support for Django releases older than 4.1 will be removed in community.general version 9.0.0 (estimated to be released in May 2024). Please notice that Django 4.1 requires Python 3.8 or greater.

  • virtualenv ( must be installed on the remote host if the virtualenv parameter is specified. This requirement is deprecated and will be removed in community.general version 9.0.0.

  • This module will create a virtualenv if the virtualenv parameter is specified and a virtual environment does not already exist at the given location. This behavior is deprecated and will be removed in community.general version 9.0.0.

  • The parameter virtualenv will remain in use, but it will require the specified virtualenv to exist. The recommended way to create one in Ansible is by using ansible.builtin.pip.

  • This module assumes English error messages for the createcachetable command to detect table existence, unfortunately.

  • To be able to use the migrate command with django versions < 1.7, you must have south installed and added as an app in your settings.

  • To be able to use the collectstatic command, you must have enabled staticfiles in your settings.

  • Your application must be executable (rwxr-xr-x), and must have a valid shebang, i.e. #!/usr/bin/env python, for invoking the appropriate Python interpreter.

See Also

See also

django-admin and Reference

Reference for django-admin or commands.

Django Download page

The page showing how to get Django and the timeline of supported releases.

What Python version can I use with Django?

From the Django FAQ, the response to Python requirements for the framework.


- name: Run cleanup on the application installed in django_dir
    command: cleanup
    project_path: "{{ django_dir }}"

- name: Load the initial_data fixture into the application
    command: loaddata
    project_path: "{{ django_dir }}"
    fixtures: "{{ initial_data }}"

- name: Run syncdb on the application
    command: syncdb
    project_path: "{{ django_dir }}"
    settings: "{{ settings_app_name }}"
    pythonpath: "{{ settings_dir }}"
    virtualenv: "{{ virtualenv_dir }}"

- name: Run the SmokeTest test case from the main app. Useful for testing deploys
    command: test
    project_path: "{{ django_dir }}"
    apps: main.SmokeTest

- name: Create an initial superuser
    command: "createsuperuser --noinput --username=admin [email protected]"
    project_path: "{{ django_dir }}"


  • Alexei Znamensky (@russoz)

  • Scott Anderson (@tastychutney)