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))