apt

APT module.

exception spicerack.apt.AptGetError[source]

Bases: SpicerackError

Custom base exception class for errors in the AptGetHosts class.

class spicerack.apt.AptGetHosts(remote_hosts: spicerack.remote.RemoteHosts) None[source]

Bases: RemoteHostsAdapter

Class to manage packages via apt-get.

Examples

>>> hosts = spicerack.remote().query('A:myalias')
>>> apt_get = spicerack.apt_get(hosts)

Initialize the instance.

Parameters:

remote_hosts (spicerack.remote.RemoteHosts) -- the instance to act on the remote hosts.

install(*packages: str, **kwargs: Any) collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]][source]

Apt-get install the provided packages.

Install the provided packages keeping the existing configuration files (typically managed by Puppet) in a non-interactive way that confirms the installation of new additional binary packages (which e.g. can happen if a package pulls in a new dependency).

Warning

This can fail if unable to get the apt lock on the host because other apt operations are ongoing, including but not limited to, the periodic Puppet run that performs apt-get update before every run. Consider wrapping it in a wmflib.interactive.confirm_on_failure() call.

Notes

Downgrades of package versions are not supported as they need the --force-yes CLI argument to be passed to apt-get and that's deemed unsafe for the possibility of unwanted results.

Examples

>>> hosts = spicerack.remote().query('A:myalias')
>>> apt_get = spicerack.apt_get(hosts)
>>> apt_get.install('package1', 'package2')
>>> # Optionally pass any argument accepted by run_sync()
>>> apt_get.install('package1', 'package2', batch_size=2, print_progress_bars=False)
Parameters:
Return type:

collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]]

Returns:

The result of the installation operations, see spicerack.remote.RemoteHosts.run_sync().

run(apt_get_command: str, **kwargs: Any) collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]][source]

Execute the given apt-get command on the current hosts.

Warning

This can fail if unable to get the apt lock on the host because other apt operations are ongoing, including but not limited to, the periodic Puppet run that performs apt-get update before every run. Consider wrapping it in a wmflib.interactive.confirm_on_failure() call.

Examples

>>> hosts = spicerack.remote().query('A:myalias')
>>> apt_get = spicerack.apt_get(hosts)
>>> apt_get.run('autoclean')
>>> # Optionally pass any argument accepted by run_sync()
>>> apt_get.run('purge package1', batch_size=2, print_progress_bars=False)
Parameters:
Return type:

collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]]

Returns:

The result of the update operations, see spicerack.remote.RemoteHosts.run_sync().

update(**kwargs: Any) collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]][source]

Update the list of available packages known to apt-get.

Warning

This can fail if unable to get the apt lock on the host because other apt operations are ongoing, including but not limited to, the periodic Puppet run that performs apt-get update before every run. Consider wrapping it in a wmflib.interactive.confirm_on_failure() call.

Examples

>>> hosts = spicerack.remote().query('A:myalias')
>>> apt_get = spicerack.apt_get(hosts)
>>> apt_get.update()
>>> # Optionally pass any argument accepted by run_sync()
>>> apt_get.update(batch_size=2, print_progress_bars=False)
Parameters:

**kwargs (typing.Any) -- optional keyword arguments to be passed to the spicerack.remote.RemoteHosts.run_sync() method.

Return type:

collections.abc.Iterator[tuple[ClusterShell.NodeSet.NodeSet, ClusterShell.MsgTree.MsgTreeElem]]

Returns:

The result of the update operations, see spicerack.remote.RemoteHosts.run_sync().

spicerack.apt.APT_GET_BASE_COMMAND: str = 'DEBIAN_FRONTEND=noninteractive /usr/bin/apt-get --quiet --yes --option Dpkg::Options::="--force-confdef" --option Dpkg::Options::="--force-confold"'

The base apt-get command to execute.

spicerack.apt.APT_GET_ENVS: tuple[str, ...] = ('DEBIAN_FRONTEND=noninteractive',)

The environment variables used for all apt-get commands.

spicerack.apt.APT_GET_INSTALL_OPTIONS: tuple[str, ...] = ('--quiet', '--yes', '--option Dpkg::Options::="--force-confdef"', '--option Dpkg::Options::="--force-confold"')

The CLI arguments passed to all apt-get commands.