sous-chefs / apt

Development repository for the apt cookbook
https://supermarket.chef.io/cookbooks/apt
Apache License 2.0
202 stars 266 forks source link
apt chef chef-cookbook chef-resource hacktoberfest managed-by-terraform

apt Cookbook

Cookbook Version CI State OpenCollective OpenCollective License

This cookbook includes recipes to execute apt-get update to ensure the local APT package cache is up to date. There are recipes for managing the apt-cacher-ng caching proxy and proxy clients. It also includes a custom resource for pinning packages via /etc/apt/preferences.d.

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Requirements

Platforms

May work with or without modification on other Debian derivatives.

Chef

Cookbooks

Recipes

default

This recipe manually updates the timestamp file used to only run apt-get update if the cache is more than one day old.

This recipe should appear first in the run list of Debian or Ubuntu nodes to ensure that the package cache is up to date before managing any package resources with Chef.

This recipe also sets up a local cache directory for preseeding packages.

Including the default recipe on a node that does not support apt (such as Windows or RHEL) results in a noop.

cacher-client

Configures the node to use a apt-cacher-ng server to cache apt requests. Configuration of the server to use is located in default['apt']['cacher_client']['cacher_server'] which is a hash containing host, port, proxy_ssl, and bypass keys. Example:

{
  "apt": {
    "cacher_client": {
      "cacher_server": {
        "host": "cache_server.mycorp.dmz",
        "port": 1234,
        "proxy_ssl": true,
        "cache_bypass": {
          "download.oracle.com": "http"
        }
      }
    }
  }
}

Bypassing the cache

Occasionally you may come across repositories that do not play nicely when the node is using an apt-cacher-ng server. You can configure cacher-client to bypass the server and connect directly to the repository with the cache_bypass attribute.

To do this, you need to override the cache_bypass attribute with an hash of repositories, with each key as the repository URL and value as the protocol to use:

{
  "apt": {
    "cacher_client": {
      "cacher_server": {
        "cache_bypass": {
          "URL": "PROTOCOL"
        }
      }
    }
  }
}

For example, to prevent caching and directly connect to the repository at download.oracle.com via http and the repo at nginx.org via https

{
  "apt": {
    "cacher_client": {
      "cacher_server": {
        "cache_bypass": {
          "download.oracle.com": "http",
          "nginx.org": "https"
        }
      }
    }
  }
}

cacher-ng

Installs the apt-cacher-ng package and service so the system can provide APT caching. You can check the usage report at http://{hostname}:3142/acng-report.html.

If you wish to help the cacher-ng recipe seed itself, you must now explicitly include the cacher-client recipe in your run list after cacher-ng or you will block your ability to install any packages (ie. apt-cacher-ng).

unattended-upgrades

Installs and configures the unattended-upgrades package to provide automatic package updates. This can be configured to upgrade all packages or to just install security updates by setting ['apt']['unattended_upgrades']['allowed_origins'].

To pull just security updates, set origins_patterns to something like ["origin=Ubuntu,archive=trusty-security"] (for Ubuntu trusty) or ["origin=Debian,label=Debian-Security"] (for Debian).

Attributes

General

Caching

Unattended Upgrades

Configuration for APT

Libraries

There is an interface_ipaddress method that returns the IP address for a particular host and interface, used by the cacher-client recipe. To enable it on the server use the ['apt']['cacher_interface'] attribute.

Usage

Put recipe[apt] first in the run list. If you have other recipes that you want to use to configure how apt behaves, like new sources, notify the execute resource to run, e.g.:

template '/etc/apt/sources.list.d/my_apt_sources.list' do
  notifies :run, 'execute[apt-get update]', :immediately
end

The above will run during execution phase since it is a normal template resource, and should appear before other package resources that need the sources in the template.

Put recipe[apt::cacher-ng] in the run_list for a server to provide APT caching and add recipe[apt::cacher-client] on the rest of the Debian-based nodes to take advantage of the caching server.

If you want to cleanup unused packages, there is also the apt-get autoclean and apt-get autoremove resources provided for automated cleanup.

Resources

apt_preference

The apt_preference resource has been moved into chef-client in Chef 13.3.

See https://docs.chef.io/resource_apt_preference.html for usage details

apt_repository

The apt_repository resource has been moved into chef-client in Chef 12.9.

See https://docs.chef.io/resource_apt_repository.html for usage details

apt_update

The apt_update resource has been moved into chef-client in Chef 12.7.

See https://docs.chef.io/resource_apt_update.html for usage details

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website