From 25474f657a7779210a6fdd29d2cf7575fcdded46 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 29 Sep 2020 06:17:27 +0000 Subject: [PATCH] Fix changes detection for createcachetable (#699) (#991) (cherry picked from commit 3d19e15a7d97f2e956722522a58c612c706098f9) Co-authored-by: Mikhail Khvoinitsky --- ...99-django_manage-createcachetable-fix-idempotence.yml | 2 ++ plugins/modules/web_infrastructure/django_manage.py | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/699-django_manage-createcachetable-fix-idempotence.yml diff --git a/changelogs/fragments/699-django_manage-createcachetable-fix-idempotence.yml b/changelogs/fragments/699-django_manage-createcachetable-fix-idempotence.yml new file mode 100644 index 0000000000..1f6e4054fb --- /dev/null +++ b/changelogs/fragments/699-django_manage-createcachetable-fix-idempotence.yml @@ -0,0 +1,2 @@ +bugfixes: + - django_manage - fix idempotence for ``createcachetable`` (https://github.com/ansible-collections/community.general/pull/699). diff --git a/plugins/modules/web_infrastructure/django_manage.py b/plugins/modules/web_infrastructure/django_manage.py index a657d3ee25..bd4d566083 100644 --- a/plugins/modules/web_infrastructure/django_manage.py +++ b/plugins/modules/web_infrastructure/django_manage.py @@ -164,8 +164,8 @@ def _ensure_virtualenv(module): os.environ["VIRTUAL_ENV"] = venv_param -def createcachetable_filter_output(line): - return "Already exists" not in line +def createcachetable_check_changed(output): + return "already exists" not in output def flush_filter_output(line): @@ -282,7 +282,7 @@ def main(): rc, out, err = module.run_command(cmd, cwd=app_path) if rc != 0: if command == 'createcachetable' and 'table' in err and 'already exists' in err: - out = 'Already exists.' + out = 'already exists.' else: if "Unknown command:" in err: _fail(module, cmd, err, "Unknown django command: %s" % command) @@ -296,6 +296,9 @@ def main(): filtered_output = list(filter(filt, lines)) if len(filtered_output): changed = True + check_changed = globals().get("{0}_check_changed".format(command), None) + if check_changed: + changed = check_changed(out) module.exit_json(changed=changed, out=out, cmd=cmd, app_path=app_path, virtualenv=virtualenv, settings=module.params['settings'], pythonpath=module.params['pythonpath'])