community.general.django_manage – Manages a Django application.

Note

This plugin is part of the community.general collection (version 1.3.6).

To install it use: ansible-galaxy collection install community.general.

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

Synopsis

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

Requirements

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

  • virtualenv

  • django

Parameters

Parameter Choices/Defaults Comments
apps
string
A list of space-delimited apps to target. Used by the test command.
cache_table
string
The name of the table used for database-backed caching. Used by the createcachetable command.
clear
boolean
    Choices:
  • no ←
  • yes
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.
command
string / required
The name of the Django management command to run. Built in commands are cleanup, collectstatic, flush, loaddata, migrate, syncdb, test, and validate.
Other commands can be entered, but will fail if they're unknown to Django. Other commands that may prompt for user input should be run with the --noinput flag.
The module will perform some basic parameter validation (when applicable) to the commands cleanup, collectstatic, createcachetable, flush, loaddata, migrate, syncdb, test, and validate.
database
string
The database to target. Used by the createcachetable, flush, loaddata, syncdb, and migrate commands.
failfast
boolean
    Choices:
  • no ←
  • yes
Fail the command immediately if a test fails. Used by the test command.

aliases: fail_fast
fixtures
string
A space-delimited list of fixture file names to load in the database. Required by the loaddata command.
link
boolean
    Choices:
  • no
  • yes
Will create links to the files instead of copying them, you can only use this parameter with collectstatic command.
liveserver
string
This parameter was implemented a long time ago in a galaxy far way. It probably relates to the django-liveserver package, which is no longer updated.
Hence, it will be considered DEPRECATED and should be removed in a future release.

aliases: live_server
merge
boolean
    Choices:
  • no
  • yes
Will run out-of-order or missing migrations as they are not rollback migrations, you can only use this parameter with migrate command.
project_path
path / required
The path to the root of the Django application where manage.py lives.

aliases: app_path, chdir
pythonpath
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.

aliases: python_path
settings
path
The Python path to the application's settings module, such as myapp.settings.
skip
boolean
    Choices:
  • no
  • yes
Will skip over out-of-order missing migrations, you can only use this parameter with migrate command.
testrunner
string
From the Django docs: Controls the test runner class that is used to execute tests.
This parameter is passed as-is to manage.py.

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

aliases: virtual_env

Notes

Note

  • virtualenv (http://www.virtualenv.org) must be installed on the remote host if the virtualenv parameter is specified.

  • This module will create a virtualenv if the virtualenv parameter is specified and a virtualenv does not already exist at the given location.

  • 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 manage.py 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.

Examples

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

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

- name: Run syncdb on the application
  community.general.django_manage:
    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
  community.general.django_manage:
    command: test
    project_path: "{{ django_dir }}"
    apps: main.SmokeTest

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

Authors

  • Scott Anderson (@tastychutney)