setting.pp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. define apt::setting (
  2. $priority = 50,
  3. $ensure = file,
  4. $source = undef,
  5. $content = undef,
  6. $notify_update = true,
  7. ) {
  8. include 'apt::params'
  9. if $content and $source {
  10. fail('apt::setting cannot have both content and source')
  11. }
  12. if !$content and !$source {
  13. fail('apt::setting needs either of content or source')
  14. }
  15. validate_re($ensure, ['file', 'present', 'absent'])
  16. validate_bool($notify_update)
  17. $title_array = split($title, '-')
  18. $setting_type = $title_array[0]
  19. $base_name = join(delete_at($title_array, 0), '-')
  20. validate_re($setting_type, ['\Aconf\z', '\Apref\z', '\Alist\z'], "apt::setting resource name/title must start with either 'conf-', 'pref-' or 'list-'")
  21. unless is_integer($priority) {
  22. # need this to allow zero-padded priority.
  23. validate_re($priority, '^\d+$', 'apt::setting priority must be an integer or a zero-padded integer')
  24. }
  25. if $source {
  26. validate_string($source)
  27. }
  28. if $content {
  29. validate_string($content)
  30. }
  31. if ($setting_type == 'list') or ($setting_type == 'pref') {
  32. $_priority = ''
  33. } else {
  34. $_priority = $priority
  35. }
  36. $_path = $::apt::params::config_files[$setting_type]['path']
  37. $_ext = $::apt::params::config_files[$setting_type]['ext']
  38. if $notify_update {
  39. $_notify = Class['apt::update']
  40. } else {
  41. $_notify = undef
  42. }
  43. file { "${_path}/${_priority}${base_name}${_ext}":
  44. ensure => $ensure,
  45. owner => 'root',
  46. group => 'root',
  47. mode => '0644',
  48. content => $content,
  49. source => $source,
  50. notify => $_notify,
  51. }
  52. }