community.general.django_manage (8.5.0) — module

Manages a Django application

Authors: Alexei Znamensky (@russoz), Scott Anderson (@tastychutney)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

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


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Run cleanup on the application installed in django_dir
  community.general.django_manage:
    command: cleanup
    project_path: "{{ django_dir }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Load the initial_data fixture into the application
  community.general.django_manage:
    command: loaddata
    project_path: "{{ django_dir }}"
    fixtures: "{{ initial_data }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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 }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create an initial superuser
  community.general.django_manage:
    command: "createsuperuser --noinput --username=admin --email=admin@example.com"
    project_path: "{{ django_dir }}"

Inputs

    
apps:
    description:
    - A list of space-delimited apps to target. Used by the V(test) command.
    required: false
    type: str

link:
    description:
    - Will create links to the files instead of copying them, you can only use this parameter
      with V(collectstatic) command.
    required: false
    type: bool

skip:
    description:
    - Will skip over out-of-order missing migrations, you can only use this parameter
      with V(migrate) command.
    required: false
    type: bool

clear:
    default: false
    description:
    - Clear the existing files before trying to copy or link the original file.
    - Used only with the V(collectstatic) command. The C(--noinput) argument will be added
      automatically.
    required: false
    type: bool

merge:
    description:
    - Will run out-of-order or missing migrations as they are not rollback migrations,
      you can only use this parameter with V(migrate) command.
    required: false
    type: bool

command:
    description:
    - The name of the Django management command to run. The commands listed below are
      built in this module and have some basic parameter validation.
    - 'V(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 V(clearsessions) instead.

      '
    - V(collectstatic) - Collects the static files into C(STATIC_ROOT).
    - V(createcachetable) - Creates the cache tables for use with the database cache backend.
    - V(flush) - Removes all data from the database.
    - V(loaddata) - Searches for and loads the contents of the named O(fixtures) into
      the database.
    - V(migrate) - Synchronizes the database state with models and migrations.
    - 'V(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 V(migrate)
      instead.

      '
    - V(test) - Runs tests for all installed apps.
    - 'V(validate) - Validates all installed models (deprecated in Django 1.7). This parameter
      will be removed in community.general 9.0.0. Use V(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 C(--noinput) flag.
    required: true
    type: str

database:
    description:
    - The database to target. Used by the V(createcachetable), V(flush), V(loaddata),
      V(syncdb), and V(migrate) commands.
    required: false
    type: str

failfast:
    aliases:
    - fail_fast
    default: false
    description:
    - Fail the command immediately if a test fails. Used by the V(test) command.
    required: false
    type: bool

fixtures:
    description:
    - A space-delimited list of fixture file names to load in the database. B(Required)
      by the V(loaddata) command.
    required: false
    type: str

settings:
    description:
    - The Python path to the application's settings module, such as V(myapp.settings).
    required: false
    type: path

pythonpath:
    aliases:
    - python_path
    description:
    - 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 O(pythonpath)'s value to the E(PYTHONPATH) environment
      variable.
    required: false
    type: path

testrunner:
    aliases:
    - test_runner
    description:
    - Controls the test runner class that is used to execute tests.
    - This parameter is passed as-is to C(manage.py).
    required: false
    type: str

virtualenv:
    aliases:
    - virtual_env
    description:
    - An optional path to a C(virtualenv) installation to use while running the manage
      application.
    type: path

cache_table:
    description:
    - The name of the table used for database-backed caching. Used by the V(createcachetable)
      command.
    required: false
    type: str

project_path:
    aliases:
    - app_path
    - chdir
    description:
    - The path to the root of the Django application where C(manage.py) lives.
    required: true
    type: path

ack_venv_creation_deprecation:
    description:
    - When a O(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 V(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.
    type: bool
    version_added: 5.8.0
    version_added_collection: community.general

See also