diff --git a/changelogs/fragments/apt_recommends.yml b/changelogs/fragments/apt_recommends.yml new file mode 100644 index 00000000000..a6e517177d0 --- /dev/null +++ b/changelogs/fragments/apt_recommends.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - apt - install recommended packages when installing package via deb file (https://github.com/ansible/ansible/issues/29726). diff --git a/lib/ansible/modules/apt.py b/lib/ansible/modules/apt.py index 33d33731067..296b1833790 100644 --- a/lib/ansible/modules/apt.py +++ b/lib/ansible/modules/apt.py @@ -886,6 +886,11 @@ def install_deb( except Exception as e: m.fail_json(msg="Unable to install package: %s" % to_native(e)) + # Install 'Recommends' of this deb file + if install_recommends: + pkg_recommends = get_field_of_deb(m, deb_file, "Recommends") + deps_to_install.extend([pkg_name.strip() for pkg_name in pkg_recommends.split()]) + # and add this deb to the list of packages to install pkgs_to_install.append(deb_file) diff --git a/test/integration/targets/apt/tasks/url-with-deps.yml b/test/integration/targets/apt/tasks/url-with-deps.yml index 7c70eb903b0..7e628c95b75 100644 --- a/test/integration/targets/apt/tasks/url-with-deps.yml +++ b/test/integration/targets/apt/tasks/url-with-deps.yml @@ -48,9 +48,37 @@ - dpkg_result is successful - dpkg_result.rc == 0 + - name: Install package from local repo + apt: + deb: "{{ repodir }}/dists/stable/main/binary-all/baz_1.0.0_all.deb" + install_recommends: yes + register: apt_url_deps + + - name: check to make sure we installed the package + shell: dpkg -l | grep baz + failed_when: False + register: baz_dpkg_result + + - name: check to make sure we installed the package's recommends + shell: dpkg -l | grep rolldice + failed_when: False + register: rolldice_dpkg_result + + - name: verify real installation of bar + assert: + that: + - apt_url_deps is changed + - baz_dpkg_result is successful + - baz_dpkg_result.rc == 0 + - rolldice_dpkg_result is successful + - rolldice_dpkg_result.rc == 0 + always: - - name: uninstall echo-hello with apt + - name: uninstall packages with apt apt: - pkg: echo-hello + pkg: + - echo-hello + - rolldice + - baz state: absent purge: yes diff --git a/test/integration/targets/setup_deb_repo/files/package_specs/stable/baz-1.0.0 b/test/integration/targets/setup_deb_repo/files/package_specs/stable/baz-1.0.0 new file mode 100644 index 00000000000..1e5d0a4a1fd --- /dev/null +++ b/test/integration/targets/setup_deb_repo/files/package_specs/stable/baz-1.0.0 @@ -0,0 +1,11 @@ +Section: misc +Priority: optional +Standards-Version: 2.3.3 + +Package: baz +Version: 1.0.0 +Section: system +Maintainer: John Doe +Architecture: all +Description: Dummy package +Recommends: rolldice