cat $dir/* > $check && visudoers -cf $check && cat $check >
/etc/sudoers
get it all done in a one-liner that early-outs on error. $check is just
file { $check: ensure => file, mode => 600, owner => root, }
to make sure it is there with the right properties.
For what it's worth, here is a simple sudo class.
It works on distros that provide the /etc/sudoers.d directory.
Tested on debian squeeze.
--vagn
define sudo::sudoer() {
$username = "$name"
include sudo
file { "/etc/sudoers.d/$username":
content => "$username ALL=(ALL) ALL\n",
mode => 440, owner => root, group => root,
require => Package[ "sudo" ],
}
}
define sudo::nopasswd() {
$username = "$name"
include sudo
file { "/etc/sudoers.d/$username":
content => "$username ALL=NOPASSWD: ALL\n",
mode => 440, owner => root, group => root,
require => Package[ "sudo" ],
}
}
class sudo() {
package { "sudo":
ensure => installed,
}
file { "/usr/bin/sus":
content => "if [ $# -eq 0 ] ; then exec sudo su - ;
else exec sudo \"$@\" ; fi",
mode => 775, owner => root, group => root,
require => Package[ "sudo" ],
}
}
The OP's problem is that he is not including the header
fragment in "Assemble_Sudo_Fragments". It is easy to miss
because
1. the code is noisy, he should get rid of those long interpolations
in the resources
2. he is handling the header fragment outside of the fragment directory,
complicating the design.
I didn't spot the logic error until I rewrote the thing:
class s_sudo ( $wheel_req_password = true)
inherits s_sudo::params
{
$dir = "${s_sudo::params::sudo_fragment_directory}"
$hdr = "${s_sudo::params::sudo_header_file}"
$hdr_tt = "s_sudo/00-sudobase.erb"
$check = "${s_sudo::params::sudo_check_file}"
file {"Sudoer_File":
path => "/etc/sudoers",
ensure => file,
mode => 440,
owner => root,
group => root,
}
file { "Sudo_Fragment_Directory":
path => "${dir}",
ensure => directory,
purge => true,
recurse => true,
}
file { "Sudo_Check_File":
path => "${check}",
ensure => file,
mode => 644,
}
file {"Sudo_Header":
path => "${hdr}",
content => template($hdr_tt),
}
exec { "Assemble_Sudo_Fragments":
command => "/bin/cat ${hdr} ${dir}/* > ${check}",
# <=== error was here
refreshonly => true,
subscribe => File[
"Sudoer_File",
"Sudo_Fragment_Directory",
"Sudo_Check_File",
"Sudo_Header",
],
notify => Exec["Check_And_Instantiate"],
}
exec {"Check_And_Instantiate":
command => "visudo -cf ${check} && cat ${check} >
/etc/sudoers",
refreshonly => true,
}
}
I wonder what would happen if he spelled his
dependency chain like this:
### Validate sudo file before making live
Exec["Assemble_Sudo_Fragments"] ~> Exec["Validate_Check_File"] ~>
File["Make_Sudo_File_Live"]
Note a string of ~>, rather than a mixed string.
Is ~> -> even sensible? Shoudn't puppet turn that
2nd dependency from -> into ~>?
--
vagn