# Install sudo and sudoers file.
#
class sudo {

    package { "sudo":
        ensure => installed,
    }

    file { "/etc/sudoers.d":
        ensure  => directory,
        mode    => 0440,
        owner   => root,
        group   => root,
        purge   => true,
        force   => true,
        recurse => true,
        source  => "puppet:///modules/custom/empty",
        require => Package["sudo"],
    }

    file { "/etc/sudoers":
        ensure  => present,
        mode    => 0440,
        owner   => root,
        group   => root,
        source  => "puppet:///modules/sudo/sudoers",
        require => File["/etc/sudoers.d"],
    }

}

# Add sudoer.
#
# === Parameters
#
#   $name:
#       User or group. Prefix group name with %.
#   $where:
#       Defaults to ALL.
#   $as_whom:
#       Defaults to ALL.
#   $what:
#       Defaults to ALL.
#
define sudo::sudoer($where="ALL", $as_whom="ALL", $what="ALL") {

    file { "/etc/sudoers.d/${name}":
        ensure  => present,
        mode    => 0440,
        owner   => root,
        group   => root,
        content => "${name}\t${where}=(${as_whom})\t${what}\n",
        require => File["/etc/sudoers"],
    }

}
