README 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. Overview
  2. ========
  3. This module manages apt on Debian.
  4. It keeps dpkg's and apt's databases as well as the keyrings for securing
  5. package download current.
  6. backports.debian.org is added.
  7. /etc/apt/sources.list and /etc/apt/preferences are managed. More
  8. recent Debian releases are pinned to very low values by default to
  9. prevent accidental upgrades.
  10. Ubuntu support is lagging behind but not absent either.
  11. ! Upgrade Notice !
  12. * The apt::codename parameter has been removed. In its place, the
  13. debian_codename fact may be overridden via an environment variable. This
  14. will affect all other debian_* facts, and achieve the same result.
  15. FACTER_debian_codename=jessie puppet agent -t
  16. * If you were using custom 50unattended-upgrades.${::lsbdistcodename} in your
  17. site_apt, these are no longer supported. You should migrate to passing
  18. $blacklisted_packages to the apt::unattended_upgrades class.
  19. * the apt class has been moved to a paramterized class. if you were including
  20. this class before, after passing some variables, you will need to move to
  21. instantiating the class with those variables instead. For example, if you
  22. had the following in your manifests:
  23. $apt_debian_url = 'http://localhost:9999/debian/'
  24. $apt_use_next_release = true
  25. include apt
  26. you will need to remove the variables, and the include and instead do
  27. the following:
  28. class { 'apt': debian_url => 'http://localhost:9999/debian/', use_next_release => true }
  29. previously, you could manually set $lsbdistcodename which would enable forced
  30. upgrades, but because this is a top-level facter variable, and newer puppet
  31. versions do not let you assign variables to other namespaces, this is no
  32. longer possible. However, there is a way to obtain this functionality, and
  33. that is to pass the 'codename' parameter to the apt class, which will change
  34. the sources.list and preferences files to be the codename you set, allowing
  35. you to trigger upgrades:
  36. include apt::dist_upgrade
  37. class { 'apt': codename => 'wheezy', notify => Exec['apt_dist-upgrade'] }
  38. * the apticron class has been moved to a parameterized class. if you were
  39. including this class before, you will need to move to instantiating the
  40. class instead. For example, if you had the following in your manifests:
  41. $apticron_email = 'foo@example.com'
  42. $apticron_notifynew = '1'
  43. ... any $apticron_* variables
  44. include apticron
  45. you will need to remove the variables, and the include and instead do the
  46. following:
  47. class { 'apt::apticron': email => 'foo@example.com', notifynew => '1' }
  48. * the apt::listchanges class has been moved to a paramterized class. if you
  49. were including this class before, after passing some variables, you will need
  50. to move to instantiating the class with those variables instead. For example,
  51. if you had the following in your manifests:
  52. $apt_listchanges_email = 'foo@example.com'
  53. ... any $apt_listchanges_* variables
  54. include apt::listchanges
  55. you will need to remove the variables, and the include and instead do the
  56. following:
  57. class { 'apt::listchanges': email => 'foo@example.com' }
  58. * the apt::proxy_client class has been moved to a paramterized class. if you
  59. were including this class before, after passing some variables, you will need
  60. to move to instantiating the class with those variables instead. For example,
  61. if you had the following in your manifests:
  62. $apt_proxy = 'http://proxy.domain'
  63. $apt_proxy_port = 666
  64. include apt::proxy_client
  65. you will need to remove the variables, and the include and instead do the
  66. following:
  67. class { 'apt::proxy_client': proxy => 'http://proxy.domain', port => '666' }
  68. Requirements
  69. ============
  70. This module needs:
  71. - the lsb-release package should be installed on the server prior to running
  72. puppet. otherwise, all of the $::lsb* facts will be empty during runs.
  73. - the common module: https://gitlab.com/shared-puppet-modules-group/common
  74. By default, on normal hosts, this module sets the configuration option
  75. DSelect::Clean to 'auto'. On virtual servers, the value is set by default to
  76. 'pre-auto', because virtual servers are usually more space-bound and have better
  77. recovery mechanisms via the host:
  78. From apt.conf(5), 0.7.2:
  79. "Cache Clean mode; this value may be one of always, prompt, auto,
  80. pre-auto and never. always and prompt will remove all packages
  81. from the cache after upgrading, prompt (the default) does so
  82. conditionally. auto removes only those packages which are no
  83. longer downloadable (replaced with a new version for
  84. instance). pre-auto performs this action before downloading new
  85. packages."
  86. To change the default setting for DSelect::Clean, you can create a file named
  87. "03clean" or "03clean_vserver" in your site_apt module's files directory. You
  88. can also define this for a specific host by creating a file in a subdirectory of
  89. the site_apt modules' files directory that is named the same as the
  90. host. (example: site_apt/files/some.host.com/03clean, or
  91. site_apt/files/some.host.com/03clean_vserver)
  92. Classes
  93. =======
  94. apt
  95. ---
  96. The apt class sets up most of the documented functionality. To use functionality
  97. that is not enabled by default, you must set one of the following parameters.
  98. Example usage:
  99. class { 'apt': use_next_release => true, debian_url => 'http://localhost:9999/debian/' }
  100. Class parameters:
  101. * use_lts
  102. If this variable is set to true the CODENAME-lts sources (such as
  103. squeeze-lts) are added.
  104. By default this is false for backward compatibility with older
  105. versions of this module.
  106. * use_volatile
  107. If this variable is set to true the CODENAME-updates sources (such as
  108. squeeze-updates) are added.
  109. By default this is false for backward compatibility with older
  110. versions of this module.
  111. * include_src
  112. If this variable is set to true a deb-src source is added for every
  113. added binary archive source.
  114. By default this is false for backward compatibility with older
  115. versions of this module.
  116. * use_next_release
  117. If this variable is set to true the sources for the next Debian
  118. release are added. The default pinning configuration pins it to very
  119. low values.
  120. By default this is false for backward compatibility with older
  121. versions of this module.
  122. * debian_url, security_url, backports_url, volatile_url
  123. These variables allow to override the default APT mirrors respectively
  124. used for the standard Debian archives, the Debian security archive,
  125. the Debian official backports and the Debian Volatile archive.
  126. * ubuntu_url
  127. These variables allows to override the default APT mirror used for all
  128. standard Ubuntu archives (including updates, security, backports).
  129. * repos
  130. If this variable is set the default repositories list ("main contrib non-free")
  131. is overriden.
  132. * disable_update
  133. Disable "apt-get update" which is normally triggered by apt::upgrade_package
  134. and apt::dist_upgrade.
  135. Note that nodes can be updated once a day by using
  136. APT::Periodic::Update-Package-Lists "1";
  137. in i.e. /etc/apt/apt.conf.d/80_apt_update_daily.
  138. * custom_preferences
  139. For historical reasons (Debian Lenny's version of APT did not support the use
  140. of the preferences.d directory for putting fragments of 'preferences'), this
  141. module will manage a default generic apt/preferences file with more
  142. recent releases pinned to very low values so that any package
  143. installation will not accidentally pull in packages from those suites
  144. unless you explicitly specify the version number. This file will be
  145. complemented with all of the preferences_snippet calls (see below).
  146. If the default preferences template doesn't suit your needs, you can create a
  147. template located in your site_apt module, and set custom_preferences with the
  148. content (eg. custom_preferences => template('site_apt/preferences') )
  149. Setting this variable to false before including this class will force the
  150. apt/preferences file to be absent:
  151. class { 'apt': custom_preferences => false }
  152. * custom_sources_list
  153. By default this module will use a basic apt/sources.list template with
  154. a generic Debian mirror. If you need to set more specific sources,
  155. e.g. changing the sections included in the source, etc. you can set
  156. this variable to the content that you desire to use instead.
  157. For example, setting this variable will pull in the
  158. templates/site_apt/sources.list file:
  159. class { 'apt': custom_sources_list => template('site_apt/sources.list') }
  160. * custom_key_dir
  161. If you have different apt-key files that you want to get added to your
  162. apt keyring, you can set this variable to a path in your fileserver
  163. where individual key files can be placed. If this is set and keys
  164. exist there, this module will 'apt-key add' each key.
  165. The debian-archive-keyring package is installed and kept current up to the
  166. latest revision (this includes the backports archive keyring).
  167. apt::apticron
  168. -------------
  169. When you instantiate this class, apticron will be installed, with the following
  170. defaults, which you are free to change:
  171. $ensure_version = 'installed',
  172. $config = "apt/${::operatingsystem}/apticron_${::lsbdistcodename}.erb",
  173. $email = 'root',
  174. $diff_only = '1',
  175. $listchanges_profile = 'apticron',
  176. $system = false,
  177. $ipaddressnum = false,
  178. $ipaddresses = false,
  179. $notifyholds = '0',
  180. $notifynew = '0',
  181. $customsubject = ''
  182. Example usage:
  183. class { 'apt::apticron': email => 'foo@example.com', notifynew => '1' }
  184. apt::cron::download
  185. -------------------
  186. This class sets up cron-apt so that it downloads upgradable packages, does not
  187. actually do any upgrade and emails when the output changes.
  188. cron-apt defaults to run at 4 AM. You may want to set the
  189. $apt_cron_hours variable before you include the class: its value will
  190. be passed as the "hours" parameter of a cronjob. Example:
  191. # Run cron-apt every three hours
  192. $apt_cron_hours = '*/3'
  193. Note that the default 4 AM cronjob won't be disabled.
  194. apt::cron::dist_upgrade
  195. -----------------------
  196. This class sets up cron-apt so that it dist-upgrades the system and
  197. emails when upgrades are performed.
  198. See apt::cron::download above if you need to run cron-apt more often
  199. than once a day.
  200. apt::dist_upgrade
  201. -----------------
  202. This class provides the Exec['apt_dist-upgrade'] resource that
  203. dist-upgrade's the system.
  204. This exec is set as refreshonly so including this class does not
  205. trigger any action per-se: other resources may notify it, other
  206. classes may inherit from this one and add to its subscription list
  207. using the plusignment ('+>') operator. A real-world example can be
  208. seen in the apt::dist_upgrade::initiator source.
  209. When this class is included the APT indexes are updated on every
  210. Puppet run due to the author's lack of Puppet wizardry.
  211. apt::dist_upgrade::initiator
  212. ----------------------------
  213. This class automatically dist-upgrade's the system when an initiator
  214. file's content changes. The initiator file is copied from the first
  215. available source amongst the following ones, in decreasing priority
  216. order:
  217. - puppet:///modules/site_apt/${::fqdn}/upgrade_initiator
  218. - puppet:///modules/site_apt/upgrade_initiator
  219. - puppet:///modules/apt/upgrade_initiator
  220. This is useful when one does not want to setup a fully automated
  221. upgrade process but still needs a way to manually trigger full
  222. upgrades of any number of systems at scheduled times.
  223. Beware: a dist-upgrade is triggered the first time Puppet runs after
  224. this class has been included. This is actually the single reason why
  225. this class is not enabled by default.
  226. When this class is included the APT indexes are updated on every
  227. Puppet run due to the author's lack of Puppet wizardry.
  228. apt::dselect
  229. ------------
  230. This class, when included, installs dselect and switches it to expert mode to
  231. suppress superfluous help screens.
  232. apt::listchanges
  233. ----------------
  234. This class, when instantiated, installs apt-listchanges and configures it using
  235. the following parameterized variables, which can be changed:
  236. version = 'present'
  237. config = "apt/${::operatingsystem}/listchanges_${::lsbrelease}.erb"
  238. frontend = 'pager'
  239. email = 'root'
  240. confirm = 0
  241. saveseen = '/var/lib/apt/listchanges.db'
  242. which = 'both'
  243. Example usage:
  244. class { 'apt::listchanges': email => 'foo@example.com' }
  245. apt::proxy_client
  246. -----------------
  247. This class adds the right configuration to apt to make it fetch packages via a
  248. proxy. The class parameters apt_proxy and apt_proxy_port need to be set:
  249. You can set the 'proxy' class parameter variable to the URL of the proxy that
  250. will be used. By default, the proxy will be queried on port 3142, but you can
  251. change the port number by setting the 'port' class parameter.
  252. Example:
  253. class { 'apt::proxy_client': proxy => 'http://proxy.domain', port => '666' }
  254. apt::reboot_required_notify
  255. ---------------------------
  256. This class installs a daily cronjob that checks if a package upgrade
  257. requires the system to be rebooted; if so, cron sends a notification
  258. email to root.
  259. apt::unattended_upgrades
  260. ------------------------
  261. If this class is included, it will install the package 'unattended-upgrades'
  262. and configure it to daily upgrade the system.
  263. The class has the following parameters that you can use to change the contents
  264. of the configuration file. The values shown here are the default values:
  265. * $config_content = undef
  266. * $config_template = 'apt/50unattended-upgrades.erb'
  267. * $mailonlyonerror = true
  268. * $mail_recipient = 'root'
  269. * $blacklisted_packages = []
  270. Note that using $config_content actually specifies all of the configuration
  271. contents and thus makes the other parameters useless.
  272. example:
  273. class { 'apt::unattended_upgrades':
  274. config_template => 'site_apt/50unattended-upgrades.jessie',
  275. blacklisted_packages => [
  276. 'libc6', 'libc6-dev', 'libc6-i686', 'mysql-server', 'redmine', 'nodejs',
  277. 'bird'
  278. ],
  279. }
  280. Defines
  281. =======
  282. apt::apt_conf
  283. -------------
  284. Creates a file in the apt/apt.conf.d directory to easily add configuration
  285. components. One can use either the 'source' meta-parameter to specify a list of
  286. static files to include from the puppet fileserver or the 'content'
  287. meta-parameter to define content inline or with the help of a template.
  288. Example:
  289. apt::apt_conf { '80download-only':
  290. source => 'puppet:///modules/site_apt/80download-only',
  291. }
  292. apt::preferences_snippet
  293. ------------------------
  294. A way to add pinning information to files in /etc/apt/preferences.d/
  295. Example:
  296. apt::preferences_snippet {
  297. 'irssi-plugin-otr':
  298. release => 'squeeze-backports',
  299. priority => 999;
  300. }
  301. apt::preferences_snippet {
  302. 'unstable_fallback':
  303. package => '*',
  304. release => 'unstable',
  305. priority => 1;
  306. }
  307. apt::preferences_snippet {
  308. 'ttdnsd':
  309. pin => 'origin deb.torproject.org',
  310. priority => 999;
  311. }
  312. The names of the resources will be used as the names of the files in the
  313. preferences.d directory, so you should ensure that resource names follow the
  314. prescribed naming scheme.
  315. From apt_preferences(5):
  316. Note that the files in the /etc/apt/preferences.d directory are parsed in
  317. alphanumeric ascending order and need to obey the following naming
  318. convention: The files have no or "pref" as filename extension and which
  319. only contain alphanumeric, hyphen (-), underscore (_) and period (.)
  320. characters - otherwise they will be silently ignored.
  321. apt::preseeded_package
  322. ----------------------
  323. This simplifies installation of packages for which you wish to preseed the
  324. answers to debconf. For example, if you wish to provide a preseed file for the
  325. locales package, you would place the locales.seed file in
  326. 'site_apt/templates/${::lsbdistcodename}/locales.seeds' and then include the
  327. following in your manifest:
  328. apt::preseeded_package { locales: }
  329. You can also specify the content of the seed via the content parameter,
  330. for example:
  331. apt::preseeded_package { 'apticron':
  332. content => 'apticron apticron/notification string root@example.com',
  333. }
  334. apt::sources_list
  335. -----------------
  336. Creates a file in the apt/sources.list.d directory to easily add additional apt
  337. sources. One can use either the 'source' meta-parameter to specify a list of
  338. static files to include from the puppet fileserver or the 'content'
  339. meta-parameter to define content inline or with the help of a template. Ending
  340. the resource name in '.list' is optional: it will be automatically added to the
  341. file name if not present in the resource name.
  342. Example:
  343. apt::sources_list { 'company_internals':
  344. source => [ "puppet:///modules/site_apt/${::fqdn}/company_internals.list",
  345. 'puppet:///modules/site_apt/company_internals.list' ],
  346. }
  347. apt::key
  348. --------
  349. Deploys a secure apt OpenPGP key. This usually accompanies the
  350. sources.list snippets above for third party repositories. For example,
  351. you would do:
  352. apt::key { 'neurodebian.gpg':
  353. ensure => present,
  354. source => 'puppet:///modules/site_apt/neurodebian.gpg',
  355. }
  356. This deploys the key in the `/etc/apt/trusted.gpg.d` directory, which
  357. is assumed by secure apt to be binary OpenPGP keys and *not*
  358. "ascii-armored" or "plain text" OpenPGP key material. For the latter,
  359. use `apt::key::plain`.
  360. The `.gpg` extension is compulsory for `apt` to pickup the key properly.
  361. apt::key::plain
  362. ---------------
  363. Deploys a secure apt OpenPGP key. This usually accompanies the
  364. sources.list snippets above for third party repositories. For example,
  365. you would do:
  366. apt::key::plain { 'neurodebian.asc':
  367. source => 'puppet:///modules/site_apt/neurodebian.asc',
  368. }
  369. This deploys the key in the `${apt_base_dir}/keys` directory (as
  370. opposed to `$custom_key_dir` which deploys it in `keys.d`). The reason
  371. this exists on top of `$custom_key_dir` is to allow a more
  372. decentralised distribution of those keys, without having all modules
  373. throw their keys in the same directory in the manifests.
  374. Note that this model does *not* currently allow keys to be removed!
  375. Use `apt::key` instead for a more practical, revokable approach, but
  376. that needs binary keys.
  377. apt::upgrade_package
  378. --------------------
  379. This simplifies upgrades for DSA security announcements or point-releases. This
  380. will ensure that the named package is upgraded to the version specified, only if
  381. the package is installed, otherwise nothing happens. If the specified version
  382. is 'latest' (the default), then the package is ensured to be upgraded to the
  383. latest package revision when it becomes available.
  384. For example, the following upgrades the perl package to version 5.8.8-7etch1
  385. (if it is installed), it also upgrades the syslog-ng and perl-modules packages
  386. to their latest (also, only if they are installed):
  387. upgrade_package { 'perl':
  388. version => '5.8.8-7etch1';
  389. 'syslog-ng':
  390. version => latest;
  391. 'perl-modules':
  392. }
  393. Resources
  394. =========
  395. File['apt_config']
  396. ------------------
  397. Use this resource to depend on or add to a completed apt configuration
  398. Exec['apt_updated']
  399. -------------------
  400. After this point the APT indexes are up-to-date.
  401. This resource is usually used like this to ensure current packages are
  402. installed by Package resources:
  403. include apt::update
  404. Package { require => Exec['apt_updated'] }
  405. Please note that the apt::upgrade_package define automatically uses
  406. this resource so you don't have to manage this yourself if you need to
  407. make sure APT indexes are up-to-date before a package upgrade is
  408. attempted, but don't want "apt-get update" to happen on every Puppet
  409. run.
  410. Tests
  411. =====
  412. To run pupept rspec tests:
  413. bundle install --path vendor/bundle
  414. bundle exec rake spec
  415. Using different facter/puppet versions:
  416. FACTER_GEM_VERSION=1.6.10 PUPPET_GEM_VERSION=2.7.23 bundle install --path vendor/bundle
  417. bundle exec rake spec
  418. Licensing
  419. =========
  420. This puppet module is licensed under the GPL version 3 or later. Redistribution
  421. and modification is encouraged.
  422. The GPL version 3 license text can be found in the "LICENSE" file accompanying
  423. this puppet module, or at the following URL:
  424. http://www.gnu.org/licenses/gpl-3.0.html