From 4080929c8a00da5defbbc56d44e6a64c21606eed Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 15 Feb 2021 08:56:50 +0100 Subject: [PATCH] Fix undeclared result for nomad_job_info module (#1721) (#1822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix unassigned variable * Create 1721-fix-nomad_job_info-no-jobs-failure.yml * refactor usage of variables in nomad_job_info * Update changelogs/fragments/1721-fix-nomad_job_info-no-jobs-failure.yml Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit d09a558fda7255a55ad2e79eb464ad38b29cf45b) Co-authored-by: Víctor Suárez Fernández <15276132+vicsufer@users.noreply.github.com> --- .../fragments/1721-fix-nomad_job_info-no-jobs-failure.yml | 2 ++ plugins/modules/clustering/nomad/nomad_job_info.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/1721-fix-nomad_job_info-no-jobs-failure.yml diff --git a/changelogs/fragments/1721-fix-nomad_job_info-no-jobs-failure.yml b/changelogs/fragments/1721-fix-nomad_job_info-no-jobs-failure.yml new file mode 100644 index 0000000000..c3c3d804e3 --- /dev/null +++ b/changelogs/fragments/1721-fix-nomad_job_info-no-jobs-failure.yml @@ -0,0 +1,2 @@ +bugfixes: + - nomad_job_info - fix module failure when nomad client returns no jobs (https://github.com/ansible-collections/community.general/pull/1721). diff --git a/plugins/modules/clustering/nomad/nomad_job_info.py b/plugins/modules/clustering/nomad/nomad_job_info.py index 9e93532843..d10c0a0438 100644 --- a/plugins/modules/clustering/nomad/nomad_job_info.py +++ b/plugins/modules/clustering/nomad/nomad_job_info.py @@ -312,12 +312,11 @@ def run(): ) changed = False - nomad_jobs = list() + result = list() try: job_list = nomad_client.jobs.get_jobs() for job in job_list: - nomad_jobs.append(nomad_client.job.get_job(job.get('ID'))) - result = nomad_jobs + result.append(nomad_client.job.get_job(job.get('ID'))) except Exception as e: module.fail_json(msg=to_native(e))