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 puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Brian Gallew
2011-Mar-15 06:37 UTC
Re: [Puppet Users] How to get the result of a command in puppet?
On Mon, Mar 14, 2011 at 8:12 AM, duff <etienne.dufrier@googlemail.com>wrote:> 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 > >If you are actually using "puts" in your function as indicated, then your return value should be "nil". Have you tried your function this way: module Puppet::Parser::Functions newfunction(:get_latest_tag, :type => :rvalue) do |args| %x["/usr/bin/svn ls http://" + arg[0] + " | /usr/bin/tail -1"] end end This is straight Ruby code, so the result of the function is the return value of the last statement/expression evaluated. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
duff
2011-Mar-15 13:37 UTC
Re: [Puppet Users] How to get the result of a command in puppet?
Hi Brian
The problem isn''t the lack of output from the puppet custom function. I
have
written some that return results.
I used puts statements in the example to show the absence of result from the
%x[] statement without having to write some convoluted manifest and puppet
output.
The %x[] statement runs and returns a result if executed on the command line
using
> ruby myfile.rb
cmd = "/usr/bin/svn ls http://url_of_my_repositorys_tags |
/usr/bin/tail -1"
puts cmd
puts %x[ #{cmd} ]
outputs:
my_tag_name/
Any ideas why the same command would stop running once wrapped in puppet?
If I run it using system(), I get "True" as the result, but
that''s not what
I want
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to
puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en.
Brian Gallew
2011-Mar-15 16:07 UTC
Re: [Puppet Users] How to get the result of a command in puppet?
In that case I''ve got nothing. Sorry. On Mar 15, 2011, at 6:37 AM, duff wrote:> Hi Brian > > The problem isn''t the lack of output from the puppet custom function. I have written some that return results. > I used puts statements in the example to show the absence of result from the %x[] statement without having to write some convoluted manifest and puppet output.-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.