Skip to content
Snippets Groups Projects
Select Git revision
  • 7ba3c28a3354cba35b3fbbb5741b3aa0f3362fc7
  • master default protected
  • pcre
3 results

postfix_virtual.aug

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    canonical.pp 1.69 KiB
    #== Definition: postfix::canonical
    #
    #Manages content of the /etc/postfix/canonical map.
    #
    #Parameters:
    #- *name*: name of address postfix will lookup. See canonical(5).
    #- *destination*: where the emails will be delivered to. See canonical(5).
    #- *ensure*: present/absent, defaults to present.
    #
    #Requires:
    #- Class["postfix"]
    #- Postfix::Hash["/etc/postfix/canonical"]
    #- Postfix::Config["canonical_maps"] or Postfix::Config["sender_canonical_maps"] or Postfix::Config["recipient_canonical_maps"]
    #- augeas
    #
    #Example usage:
    #
    #  node "toto.example.com" {
    #
    #    include postfix
    #
    #    postfix::hash { "/etc/postfix/recipient_canonical":
    #      ensure => present,
    #    }
    #    postfix::config { "canonical_alias_maps":
    #      value => "hash:/etc/postfix/recipient_canonical"
    #    }
    #    postfix::canonical {
    #      "user@example.com":
    #        file        => "/etc/postfix/recipient_canonical",
    #        ensure      => present,
    #        destination => "root";
    #    }
    #  }
    #
    define postfix::canonical (
      $destination,
      $file=undef,
      $ensure='present'
    ) {
      include postfix
      include ::postfix::augeas
    
      $_file = pick($file, "${postfix::confdir}/canonical")
    
      case $ensure {
        'present': {
          $changes = [
            "set pattern[. = '${name}'] '${name}'",
            "set pattern[. = '${name}']/destination '${destination}'",
          ]
        }
    
        'absent': {
          $changes = "rm pattern[. = '${name}']"
        }
    
        default: {
          fail("Wrong ensure value: ${ensure}")
        }
      }
    
      augeas {"Postfix canonical - ${name}":
        incl    => $_file,
        lens    => 'Postfix_Canonical.lns',
        changes => $changes,
        require => [Package['postfix'], Augeas::Lens['postfix_canonical']],
        notify  => Exec["generate ${_file}.db"],
      }
    }