Skip to content

operations.apt.packages shows "SUCCESS/Changed" for packages, that are already installed in some caces #1026

@stone-w4tch3r

Description

@stone-w4tch3r

Describe the bug

If package's name is "alias" in apt, apt.packages will produce Change on every run, regardless of actual package's state

To Reproduce

  1. Run Ubuntu/Debian vm
  2. Run main.py 1st time:
from pyinfra.operations import apt

apt.update(
    _sudo=True,
    cache_time=86400,
)

apt.packages(
    _sudo=True,
    packages=['fortune'],
)
  1. Run again and see output:
(...)
--> Starting operation: Apt/Packages (packages=['fortune'])
    [primary.multipass] Success


--> Results:
    Groups: inventory / my_hosts
    [primary.multipass]   Changed: 1   No change: 1   Errors: 0 

Note that pyinfra counted a change, but actually nothing happend, package was already installed
4. On vm try to install package:

sudo apt install fortune -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'fortune-mod' instead of 'fortune' # <---------- [THIS]
fortune-mod is already the newest version (1:1.99.1-7build1).
0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.

From output we see, thaе fortune was not real name of package, it was resolved to fortune-mod

  • Target system information
    Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-164-generic x86_64)

Expected behavior

No SUCCESS/Changed from pyinfra when installing package by "alias"

Meta

  • Include output of pyinfra --support.
pyinfra --support
--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Linux
      Platform: Linux-6.2.0-36-generic-x86_64-with-glibc2.37
      Release: 6.2.0-36-generic
      Machine: x86_64
    pyinfra: v2.8
    Executable: /home/user/Projects/Test/venv/bin/pyinfra
    Python: 3.11.4 (CPython, GCC 12.3.0)
  • How was pyinfra installed (source/pip)?
    pip
  • Include pyinfra-debug.log (if one was created)
    none
  • Consider including output with -vv and --debug.
Verbose output
 pyinfra inventory.py main.py -vv

--> Loading config...

--> Loading inventory...

--> Connecting to hosts...
    [primary.multipass] Connected

--> Preparing Operations...
    Loading: main.py
[primary.multipass] >>> env SUDO_ASKPASS=/tmp/pyinfra-sudo-askpass-erYil8oT5EAE *** sudo -H -A -k sh -c '! (test -e /var/lib/apt/periodic/update-success-stamp || test -L /var/lib/apt/periodic/update-success-stamp ) || ( stat -c '"'"'user=%U group=%G mode=%A atime=%X mtime=%Y ctime=%Z size=%s %N'"'"' /var/lib/apt/periodic/update-success-stamp 2> /dev/null || stat -f '"'"'user=%Su group=%Sg mode=%Sp atime=%a mtime=%m ctime=%c size=%z %N%SY'"'"' /var/lib/apt/periodic/update-success-stamp )'
    [primary.multipass] Loaded fact files.File (path=/var/lib/apt/periodic/update-success-stamp)
[primary.multipass] >>> env SUDO_ASKPASS=/tmp/pyinfra-sudo-askpass-erYil8oT5EAE *** sudo -H -A -k sh -c 'date +'"'"'%Y-%m-%dT%H:%M:%S%z'"'"''
    [primary.multipass] Loaded fact server.Date
    [primary.multipass] noop: apt is already up to date
[primary.multipass] >>> env SUDO_ASKPASS=/tmp/pyinfra-sudo-askpass-erYil8oT5EAE *** sudo -H -A -k sh -c '! command -v dpkg >/dev/null || dpkg -l'
    [primary.multipass] Loaded fact deb.DebPackages
    [primary.multipass] Ready: main.py

--> Proposed changes:
    Groups: inventory / my_hosts
    [primary.multipass]   Operations: 2   Change: 1   No change: 1   


--> Beginning operation run...
--> Starting operation: Apt/Update (cache_time=86400)
    [primary.multipass] No changes

--> Starting operation: Apt/Packages (packages=['fortune'])
[primary.multipass] >>> env SUDO_ASKPASS=/tmp/pyinfra-sudo-askpass-erYil8oT5EAE *** sudo -H -A -k sh -c 'DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install fortune'
    [primary.multipass] Success


--> Results:
    Groups: inventory / my_hosts
    [primary.multipass]   Changed: 1   No change: 1   Errors: 0
    ```

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugLabel for all kind of bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions