diff --git a/pyinfra/operations/apt.py b/pyinfra/operations/apt.py index 40c54c881..ece334cae 100644 --- a/pyinfra/operations/apt.py +++ b/pyinfra/operations/apt.py @@ -363,10 +363,12 @@ def upgrade(auto_remove: bool = False): @operation() -def dist_upgrade(): +def dist_upgrade(auto_remove: bool = False): """ Updates all apt packages, employing dist-upgrade. + + auto_remove: removes transitive dependencies that are no longer needed. + **Example:** .. code:: python @@ -376,7 +378,12 @@ def dist_upgrade(): ) """ - yield from _simulate_then_perform("dist-upgrade") + command = ["dist-upgrade"] + + if auto_remove: + command.append("--autoremove") + + yield from _simulate_then_perform(" ".join(command)) @operation() diff --git a/tests/operations/apt.dist_upgrade/dist_upgrade_autoremove.json b/tests/operations/apt.dist_upgrade/dist_upgrade_autoremove.json new file mode 100644 index 000000000..a4f23e6aa --- /dev/null +++ b/tests/operations/apt.dist_upgrade/dist_upgrade_autoremove.json @@ -0,0 +1,16 @@ +{ + "kwargs": {"auto_remove": true}, + "facts": { + "apt.SimulateOperationWillChange": { + "command=dist-upgrade --autoremove": { + "upgraded": 10, + "newly_installed": 3, + "removed": 2, + "not_upgraded": 3 + } + } + }, + "commands": [ + "DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade --autoremove" + ] +}