> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
here is an example:
class apache-maven-v3 {
# prepare local filesystem
file { 'java_path':
path => "/usr/local/java",
ensure => directory,
}
# copy file from puppet master to local system
file { 'copy_maven_v3':
path => "/usr/local/java/apache-maven-3.0.3-bin.tar.gz",
source =>
"puppet:///modules/apache-maven-v3/apache-maven-3.0.3-bin.tar.gz",
}
# extract local file
exec { 'install_maven_v3':
command => "/bin/tar zxf /usr/local/java/apache-maven-3.0.3-bin.tar.gz",
cwd => "/usr/local/java",
creates => "/usr/local/java/apache-maven-3.0.3",
}
# make sure the order is set properly
File['java_path'] -> File['copy_maven_v3'] -> Exec['install_maven_v3']
}
kind regards,
Martin
puppet insists in unique resources.
Therefore you can not define the file resource for tar archive twice.
Another option would be to fetch the file via exec (wget/curl/scp),
create a flagfile afterwards and remove the archive after extraction.
Additionally you can set the unless parameter on the exec copy resource
to run only if the destination diretory does not exist.
Example:
class apache-maven-v3 {
# fetch from storage
exec { 'copy_maven_v3':
command => "curl http://...../apache-maven-v3-bin.tar.gz -o
/usr/local.... && touch /usr/local/java/copy_finished",
creates => '/usr/local/java/copy_finished',
# run only if extracted path does not exist
unless => "test -d /usr/local/java/apache-maven-v3",
}
#extract
exec { 'install_maven_v3:
...
}
# remove archive
file { 'delete_copied_archive':
path => '/usr/local/java/...',
ensure => absent,
}
}
kind regards,
Martin
Is this so bad? I would probably do something like:
$tarball_dir = "/usr/local/src"
$maven_version = "1.2.3"
file { "$tarball_dir/apache-maven-$maven_version.tar.gz":
source => "puppet:///..."
[..]
}
exec { "extract maven archive" :
command => "/usr/bin/tar xzf $tarball_dir/apache-maven-$maven_version.tar.gz -C /usr/share/java",
require => File["$tarball_dir/apache-maven-$maven_version.tar.gz"]
}
Or somesuch and leave the tarball where it is.
If you want to prune old tarballs you could do something ugly like
exec { "cleanup old maven tarballs":
command => "/bin/find $tarball_dir -name 'apache-maven-*.tar.gz'|/bin/grep -v apache-maven-$maven_version.tar.gz|/bin/xargs rm -f"
}
or do it the puppet way with a load of file { "foo": ensure => absent }
or have the first file be file { ".../apache-maven.tar.gz": source => "puppet:///.../apache-maven-$maven_version.tar.gz" } so that the filename is invariant, but the contents get replaced with whichever version you pick. This method has the advantage that you don't get a buildup of old tarballs on the node.
You could even do
exec { "download and extract mvn" :
command => "/usr/bin/curl http://foo/apache-maven-$maven_version.tar.gz|/usr/bin/tar xz -C /usr/share/java",
creates => "[...]",
}
Many ways to crack this egg, and I'm sure people will suggest others.
--
Russell Howe
rh...@moonfruit.com
> Hi Martin,
>
> Have tried this out and have noticed that the copied .gz file is left
> in /usr/share/java after unpacking. I tried adding another file
> resource to delete it but because this points to the same filepath as
> the initial resource puppet disallows it:
In my experience, having the file stick around can be helpful if you keep them somewhere out of the way. I'd download it to something like /usr/local/tar_packages and leave it there. If that's a problem, you can use /tmp, which should be cleaned occasionally by the OS. Just make sure to be careful of permissions if it's sensitive;
Ed, I am having trouble unzipping any tarball via Puppet. So I installed your module to see how you might have done it. It runs, it creates the javapath and copies the file... but I get the same error that I get on my modules... can I please ask how you made unzip work? I am on Ubuntu 10.4.1, and 2.6.4 (Puppet Enterprise 1.0).
err: /Stage[main]/Apache-maven-v3/Exec[install_maven_v3]/returns: change from notrun to 0 failed: /bin/tar zxf /usr/local/java/apache-maven-3.0.3-bin.tar.gz returned 2 instead of one of [0] at /etc/puppetlabs/puppet/modules/apache-maven-v3/manifests/init.pp:18
--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/AlqzFLkTS28/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.
From the command line all works fine, only not from Puppet. BTW, I am not the only one with this complaint online on your forums and elsewhere, people complain that Tar works, but not UnTar. -S