udo waechter
2008-Jan-19 11:33 UTC
mixing templates and other methods for a file''s content
Hello there,
I have come to a situation where I would like to mix 2 approaches to
create the contents of a file. Here is what I have:
a module ''sudo'' which manages a hosts /etc/sudoers file:
init.pp:
class sudo {
case $operatingsystem {
Debian: {
package { "sudo": }
}
}
file { "/etc/sudoers":
mode => 440, content => template("sudo/sudoers.erb"),
tag => sudo,
}
}
and sudoers.erb:
<%
musers = ""
susers = ""
IO.foreach("/etc/puppet/bootstrap/hosts.dat") do |l|
a = l.split
if a[1] == hostname
musers = a[5]
if a.length >= 8
susers = a[7]
end
break
end
end
%>
Cmnd_Alias INST = /usr/sbin/synaptic, /usr/bin/cpan, /usr/bin/apt-
get
root ALL=(ALL) ALL
%adm ALL=(ALL) ALL
#### These users can install and deinstall stuff
<% if musers.length > 0 -%>
User_Alias MAINUSERS = <%= musers %>
MAINUSERS ALL = (ALL) PASSWD: INST
<% end -%>
### These users can ''su'' to root
<% if susers.length > 0 -%>
User_Alias SUDOERS = <%= susers %>
SUDOERS ALL = (ALL) PASSWD: /bin/su
<% end -%>
======== end sudoers.erb
In the template, we read from a file (hosts.dat, on the puppetmaster),
where we store some information about our hosts. In this file we store
login names which have certain sudo permissions on certain hosts.
Now, I would like to extend the module such that I can add additional
entries in /etc/sudoers but still retain the functionality displayed
here.
Is this possible? If yes, how?
Thank you all,
udo.
--
:: udo waechter - root@zoide.net :: N 52º16''30.5" E
8º3''10.1"
:: genuine input for your ears: http://www.auriculabovinari.de
:: your eyes: http://ezag.zoide.net
:: your brain: http://www.zoide.net
Luke Kanies
2008-Jan-19 18:07 UTC
Re: mixing templates and other methods for a file''s content
On Jan 19, 2008, at 3:33 AM, udo waechter wrote:> In the template, we read from a file (hosts.dat, on the puppetmaster), > where we store some information about our hosts. In this file we store > login names which have certain sudo permissions on certain hosts. > > Now, I would like to extend the module such that I can add additional > entries in /etc/sudoers but still retain the functionality displayed > here. > > Is this possible? If yes, how?You could build up separate strings, and then concatenate them manually, I suppose. Otherwise, I think you''d have to remodel the whole thing as resources. -- You can''t build a reputation on what you are going to do. -- Henry Ford --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com