From 62d2df74b0c9d57fa043a29a2506381536a1226a Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Fri, 20 Apr 2018 07:57:14 +0200 Subject: [PATCH] apt: fix build-dep idempotency (#38999) --- lib/ansible/modules/packaging/os/apt.py | 7 ++++++- test/integration/targets/apt/tasks/apt.yml | 23 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/packaging/os/apt.py b/lib/ansible/modules/packaging/os/apt.py index 95401c38e0..2bb6712d81 100644 --- a/lib/ansible/modules/packaging/os/apt.py +++ b/lib/ansible/modules/packaging/os/apt.py @@ -578,7 +578,12 @@ def install(m, pkgspec, cache, upgrade=False, default_release=None, else: diff = {} status = True - data = dict(changed=True, stdout=out, stderr=err, diff=diff) + + changed = True + if build_dep: + changed = APT_GET_ZERO not in out + + data = dict(changed=changed, stdout=out, stderr=err, diff=diff) if rc: status = False data = dict(msg="'%s' failed: %s" % (cmd, err), stdout=out, stderr=err, rc=rc) diff --git a/test/integration/targets/apt/tasks/apt.yml b/test/integration/targets/apt/tasks/apt.yml index 0251bea489..0dd3ea36d6 100644 --- a/test/integration/targets/apt/tasks/apt.yml +++ b/test/integration/targets/apt/tasks/apt.yml @@ -213,3 +213,26 @@ with_items: - libcaca-dev - libslang2-dev + +# https://github.com/ansible/ansible/issues/38995 +- name: build-dep for a package + apt: + name: tree + state: build-dep + register: apt_result + +- name: Check the result + assert: + that: + - apt_result is changed + +- name: build-dep for a package (idempotency) + apt: + name: tree + state: build-dep + register: apt_result + +- name: Check the result + assert: + that: + - apt_result is not changed