apt
Apt package tasks¶
This module provides tasks for interacting with the apt package manager.
deb(src, present=True, force=False)
¶
Add/remove .deb
file packages.
- src: filename or URL of the
.deb
file - present: whether or not the package should exist on the system
- force: whether to force the package install by passing
--force-yes
to apt
Note
When installing, apt-get install -f
will be run to install any unmet
dependencies.
URL sources with present=False
:
If the .deb
file isn't downloaded, pyinfra can't remove any existing
package as the file won't exist until mid-deploy.
Example:
# Note: Assumes wget is installed.
apt.deb(
name="Install Chrome via deb",
src="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb",
)
dist_upgrade()
¶
Updates all apt packages, employing dist-upgrade.
Example:
apt.dist_upgrade(
name="Upgrade apt packages using dist-upgrade",
)
key(src=None, keyserver=None, keyid=None)
¶
Add apt gpg keys with apt-key
.
- src: filename or URL
- keyserver: URL of keyserver to fetch key from
- keyid: key ID or list of key IDs when using keyserver
keyserver/id: These must be provided together.
Examples:
# Note: If using URL, wget is assumed to be installed.
apt.key(
name="Add the Docker apt gpg key",
src="https://download.docker.com/linux/ubuntu/gpg",
)
apt.key(
name="Install VirtualBox key",
src="https://www.virtualbox.org/download/oracle_vbox_2016.asc",
)
packages(packages=None, present=True, latest=False, update=False, cache_time=None, upgrade=False, force=False, no_recommends=False, allow_downgrades=False)
¶
Manage packages with apt (install, uninstall, update)
Package versions can be given, as with apt, "
Parameters:
Name | Type | Description | Default |
---|---|---|---|
packages |
Optional[List[TemplateStr]]
|
List of packages (templatable) |
None
|
present |
bool
|
Should packages be installed |
True
|
latest |
bool
|
Upgrade packages (if no specific version is given) |
False
|
update |
bool
|
Run apt update before installing packages |
False
|
cache_time |
Optional[int]
|
When used with update, cache for this many seconds |
None
|
upgrade |
bool
|
Run apt upgrade before installing packages |
False
|
force |
bool
|
Force package installs by passing –force-yes to apt |
False
|
no_recommends |
bool
|
Don’t install recommended packages |
False
|
allow_downgrades |
bool
|
Allow downgrading packages with version (–allow-downgrades) |
False
|
Not yet implemented
extra_install_args: Additional arguments to the apt install command extra_uninstall_args: additional arguments to the apt uninstall command
Examples:
apt.packages(packages=["neovim"])
apt.packages(packages=["neovim"], latest=True)
ppa(src, present=True)
¶
Add/remove Ubuntu ppa repositories.
- src: the PPA name (full ppa:user/repo format)
- present: whether it should exist
Note
requires apt-add-repository
on the remote host
Example:
# Note: Assumes software-properties-common is installed.
apt.ppa(
name="Add the Bitcoin ppa",
src="ppa:bitcoin/bitcoin",
)
repo(src, present=True, filename=None)
¶
Add/remove apt repositories.
- src: apt source string eg
deb http://X hardy main
- present: whether the repo should exist on the system
- filename: optional filename to use
/etc/apt/sources.list.d/<filename>.list
. By default uses/etc/apt/sources.list
.
Example:
apt.repo(
name="Install VirtualBox repo",
src="deb https://download.virtualbox.org/virtualbox/debian bionic contrib",
)
update(cache_time=None)
¶
Updates apt repositories.
- cache_time: cache updates for this many seconds
Example:
apt.update(
name="Update apt repositories",
cache_time=3600,
)
upgrade(auto_remove=False)
¶
Upgrades all apt packages.
- autoremove: removes transitive dependencies that are no longer needed.
Example:
# Upgrade all packages
apt.upgrade(
name="Upgrade apt packages",
)
# Upgrade all packages and remove unneeded transitive dependencies
apt.upgrade(
name="Upgrade apt packages and remove unneeded dependencies"
auto_remove=True
)