Opkg Operations¶
- Manage packages on OpenWrt using opkg
update- update local copy of package informationpackages- install and remove packages
See https://openwrt.org/docs/guide-user/additional-software/opkg
OpenWrt recommends against upgrading all packages thus there is no opkg.upgrade function
Note: as of OpenWrt Release 2025.12, OpenWrt uses apk.
Facts used in these operations: opkg.OpkgPackages.
opkg.packages¶
Add/remove/update opkg packages.
opkg.packages(
packages: Union[str, List[str]] = '',
present: bool = True,
latest: bool = False,
update: bool = True,
**kwargs,
)
packages: package or list of packages to that must/must not be present
present: whether the package(s) should be installed (default True) or removed
latest: whether to attempt to upgrade the specified package(s) (default False)
update: run
opkg updatebefore installing packages (default True)
- Not Supported:
Opkg does not support version pinning, i.e.
<pkg>=<version>is not allowed and will cause an exception.
Examples:
from pyinfra.operations import opkg
# Ensure packages are installed (will not force package upgrade)
opkg.packages(['asterisk', 'vim'], name="Install Asterisk and Vim")
# Install the latest versions of packages (always check)
opkg.packages(
'vim',
latest=True,
name="Ensure we have the latest version of Vim"
)
Note
This operation also inherits all global arguments.
opkg.update¶
Stateless operation
This operation will always execute commands and is not idempotent.
Update the local opkg information.
opkg.update**kwargs, )
Note
This operation also inherits all global arguments.
pyinfra 3.x