last_updated: 2026-11-17

pyinfra changes on install#

I was wondering why I kept getting changes to install commands even though I was certain that they were run before and the package in question was installed, e.g.

$ make red
pyinfra @tofu --limit red site.py
--> Loading config...
--> Loading inventory...
--> Connecting to hosts...
    [@tofu/red]    Connected

--> Preparing operation files...
    Loading: site.py
    [@tofu/red]    Ready: site.py

--> Detected changes:
    Operation                                                                 Change          Conditional Change
    tasks/all.py | swap | remove other swapfiles                              -               -
    tasks/all.py | swap | create 2G /swapfile                                 -               1 (@tofu/red)
    tasks/all.py | swap | fstab                                               -               -
    tasks/all.py | swap | swapon                                              -               1 (@tofu/red)
    tasks/all.py | swap | install systemd-oomd                                1 (@tofu/red)   -
...

Of course this is because of apt caching. I set a cache_time of 1 hour (3600 seconds) in apt.packages:

from pyinfra.operations import apt

apt.packages(
    name='install systemd-oomd',
    packages=['systemd-oomd'],
    update=True,
    cache_time=3600,
)

On the next run, the output looks like this:

...

--> Detected changes:
    Operation                                                                 Change   Conditional Change
    tasks/all.py | swap | remove other swapfiles                              -        -
    tasks/all.py | swap | create 2G /swapfile                                 -        1 (@tofu/red)
    tasks/all.py | swap | fstab                                               -        -
    tasks/all.py | swap | swapon                                              -        1 (@tofu/red)