On Sunday, 11 September 2011 02:36:39 UTC+2, Jon Forrest wrote:
>
> [...] I want to be able to
>
> somehow expand the template files and run [some check]
> as part of a git pre-commit hook. I want this expansion to
> occur without making a normal puppet run so that the bad
> files won't get distributed.
>
> Can anybody point me to a technique for doing this?
>
> I have seen lots of interesting techniques in the reply-posts but not that
IMO satisfactorily address your original requirement. I faced a similar
problem trying to do a syntax check on perl script thrown into .erb format
to fill in some hard-coded directories and stuff. The solution I quickly
hacked together might be helpful...
The puppet server config for our datacentres are stored in a git
repository, and I have local clone on my workstation for development
($HOME/gitrepos/puppet-isa/). Starting from a copy (in a temp dir) of the
manifest that generates the script in question, I remove the surrounding
class myclass { ... }, and the include/require of other manifests. In fact
keep little more than the file resource that generates the script (with
owner => 'root', etc removed!), and assign hard-coded string values to the
variables used in the erb. One of those variables is the dir where the file
will be created and I point that to my same tmpdir! Then I just run puppet
apply to generate my script. Something like this:
$ mkdir $HOME/tmp/testpuppet
$ cd $HOME/tmp/testpuppet
$ cp $HOME/gitrepos/puppet-isa/modules/mymodule/manifests/handlers.pp
./genhandlers.pp
$ vi genhandlers.pp # edit the manifest as described above
$ cat genhandlers.pp
# genhandlers.pp - generate the handler script
$handlerdir = '/home/me/tmp/testspuppet'
# next two vars are for use in erb, normaly the values
# are taken from included config class...
# $mylibdir = $mymodule::config::mylibdir
$mylibdir = '/usr/share/mylibs'
$myconffile = '/etc/myconf.conf'
file { "${handlerdir}/myscript.pl" :
ensure => file,
content => template('mymodule/myscript.pl.erb'),
mode => '0755',
}
# EOF - genhandlers.pp
$ puppet apply --modulepath=$HOME/gitrepos/puppet-isa/modules./genhandlers.pp
$ ls -1tr
genhandlers.pp
myscript.pl
--- end example
I have no experience with commit hooks but I guess it shouldn't be hard to
wrap the above into a script. One could use a directory from mktemp and
generate a minimal manifest from a here-document or by pulling it out of
the original manifest with awk/sed...
Hope that helps,
Brandon
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.