diff --git a/changelogs/fragments/3283-django_manage-fix-command-splitting.yaml b/changelogs/fragments/3283-django_manage-fix-command-splitting.yaml new file mode 100644 index 0000000000..ba8b4efd69 --- /dev/null +++ b/changelogs/fragments/3283-django_manage-fix-command-splitting.yaml @@ -0,0 +1,2 @@ +bugfixes: + - django_manage - argument ``command`` is being splitted again as it should (https://github.com/ansible-collections/community.general/issues/3215). diff --git a/plugins/modules/web_infrastructure/django_manage.py b/plugins/modules/web_infrastructure/django_manage.py index 98ffdc446b..0c8126c457 100644 --- a/plugins/modules/web_infrastructure/django_manage.py +++ b/plugins/modules/web_infrastructure/django_manage.py @@ -158,6 +158,7 @@ EXAMPLES = """ import os import sys +import shlex from ansible.module_utils.basic import AnsibleModule @@ -273,61 +274,62 @@ def main(): ), ) - command = module.params['command'] + command_split = shlex.split(module.params['command']) + command_bin = command_split[0] project_path = module.params['project_path'] virtualenv = module.params['virtualenv'] for param in specific_params: value = module.params[param] - if value and param not in command_allowed_param_map[command]: - module.fail_json(msg='%s param is incompatible with command=%s' % (param, command)) + if value and param not in command_allowed_param_map[command_bin]: + module.fail_json(msg='%s param is incompatible with command=%s' % (param, command_bin)) - for param in command_required_param_map.get(command, ()): + for param in command_required_param_map.get(command_bin, ()): if not module.params[param]: - module.fail_json(msg='%s param is required for command=%s' % (param, command)) + module.fail_json(msg='%s param is required for command=%s' % (param, command_bin)) _ensure_virtualenv(module) - cmd = ["./manage.py", command] + run_cmd_args = ["./manage.py"] + command_split - if command in noinput_commands: - cmd.append("--noinput") + if command_bin in noinput_commands and '--noinput' not in command_split: + run_cmd_args.append("--noinput") for param in general_params: if module.params[param]: - cmd.append('--%s=%s' % (param, module.params[param])) + run_cmd_args.append('--%s=%s' % (param, module.params[param])) for param in specific_boolean_params: if module.params[param]: - cmd.append('--%s' % param) + run_cmd_args.append('--%s' % param) # these params always get tacked on the end of the command for param in end_of_command_params: if module.params[param]: - cmd.append(module.params[param]) + run_cmd_args.append(module.params[param]) - rc, out, err = module.run_command(cmd, cwd=project_path) + rc, out, err = module.run_command(run_cmd_args, cwd=project_path) if rc != 0: - if command == 'createcachetable' and 'table' in err and 'already exists' in err: + if command_bin == 'createcachetable' and 'table' in err and 'already exists' in err: out = 'already exists.' else: if "Unknown command:" in err: - _fail(module, cmd, err, "Unknown django command: %s" % command) - _fail(module, cmd, out, err, path=os.environ["PATH"], syspath=sys.path) + _fail(module, run_cmd_args, err, "Unknown django command: %s" % command_bin) + _fail(module, run_cmd_args, out, err, path=os.environ["PATH"], syspath=sys.path) changed = False lines = out.split('\n') - filt = globals().get(command + "_filter_output", None) + filt = globals().get(command_bin + "_filter_output", None) if filt: filtered_output = list(filter(filt, lines)) if len(filtered_output): changed = True - check_changed = globals().get("{0}_check_changed".format(command), None) + check_changed = globals().get("{0}_check_changed".format(command_bin), None) if check_changed: changed = check_changed(out) - module.exit_json(changed=changed, out=out, cmd=cmd, app_path=project_path, project_path=project_path, + module.exit_json(changed=changed, out=out, cmd=run_cmd_args, app_path=project_path, project_path=project_path, virtualenv=virtualenv, settings=module.params['settings'], pythonpath=module.params['pythonpath']) diff --git a/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py index 0a11583aba..f2472c1fe8 100644 --- a/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py +++ b/tests/integration/targets/django_manage/files/base_test/simple_project/p1/p1/settings.py @@ -121,3 +121,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.1/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = '/tmp/django-static' diff --git a/tests/integration/targets/django_manage/tasks/main.yaml b/tests/integration/targets/django_manage/tasks/main.yaml index ed305ca96b..0421739acc 100644 --- a/tests/integration/targets/django_manage/tasks/main.yaml +++ b/tests/integration/targets/django_manage/tasks/main.yaml @@ -48,3 +48,9 @@ pythonpath: "{{ tmp_django_root.path }}/1045-single-app-project/" command: check virtualenv: "{{ tmp_django_root.path }}/venv" + +- name: Run collectstatic --noinput on simple project + community.general.django_manage: + project_path: "{{ tmp_django_root.path }}/simple_project/p1" + command: collectstatic --noinput + virtualenv: "{{ tmp_django_root.path }}/venv"