Hello, I am trying to export the latest tag of an svn repository to a
puppet client.
To do so, I would like to run the following command to get the latest
tag
/usr/bin/svn ls http://url_to_my_svn_repository/tags | /usr/bin/
tail -1
However, I couldn't find a way to store the result of an exec in a
variable.
Since the url to the repository will change depending on the project,
I decided to use a custom function and get it to run and return the
result of the command.
module Puppet::Parser::Functions
newfunction(:get_latest_tag, :type => :rvalue) do |args|
cmd = "/usr/bin/svn ls http://" + arg[0] + " | /usr/bin/
tail -1"
puts cmd
puts %x[ #{cmd} ]
puts 'the end'
end
end
which outputs (note that the command's result is missing):
/usr/bin/svn ls http://url_to_my_svn_repository/tags | /usr/bin/
tail -1
the end
When I run the %x[#{cmd}] statement in a simple ruby file, I get the
expected result.
If I run a simple echo statement instead of the {cmd}, the result of
the cmd is actually outputted
Any idea what's wrong in my custom function? How do I get the result
of a command in puppet?
Here is an excerpt of my manifest if you need a context.
subversion::deploy{'my_site':
repourl => 'my_site/tags',
#branch => '2011031401',
copydir => '/var/www/my_site'
}
$yedzu_svn = <<<url_to_my_svn_server>>>
class subversion {
package { subversion:
ensure => installed,
}
}
define subversion::workingcopy($repourl, $branch, $copydir) {
include subversion
file { "$copydir":
owner => nginx, group => nginx, mode => 755,
ensure => directory,
#notify => subversion::checkout{$branch}
}
# initial check out
subversion::checkout{
$branch :
repourl => $repourl,
branch => $branch,
copydir => $copydir,
require => File[$copydir]
}
}
define subversion::checkout($repourl, $branch, $copydir) {
include subversion
notice("/usr/bin/svn co --non-interactive
http://$yedzu_svn/$repourl/$branch
$copydir/$branch")
exec { "svnco-$branch":
command => "/usr/bin/svn co --non-interactive
http://$yedzu_svn/$repourl/$branch $copydir/$branch",
creates => "$copydir/$branch/.svn",
require => [Package["subversion"]]
}
}
define subversion::deploy($repourl, $branch, $copydir,
$latest=false) {
include subversion
notice(get_latest_tag("$yedzu_svn/$repourl"))
subversion::workingcopy {
$branch:
repourl => $repourl,
branch => $branch,
copydir => $copydir,
#notify => subversion::symlink{$branch}
}
subversion::symlink{
$branch:
repourl => $repourl,
branch => $branch,
copydir => $copydir,
require => Exec["svnco-$branch"]
}
}
define subversion::symlink($repourl, $branch, $copydir){
notice("symlinking")
exec {
"new_current_$copydir/$branch":
command => "/bin/rm $copydir/current; /bin/ln -s
$copydir/$branch $copydir/current",
}
exec {
"current_$copydir/$branch":
command => "/bin/ln -s $copydir/$branch $copydir/
current",
}
} }
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.