Ask Your Question

unzip and copy multiple files on puppet agent

asked 2015-04-22 11:22:52 -0600

puppet-user381 gravatar image

updated 2015-04-22 11:26:26 -0600

I am trying to use puppet on AWS environment. I have a compressed file containing a war file + multiple other config files saved at a fixed url. Example: is saved at http://mydomain/

Compressed contains:
-application.war to be deployed at /etc/jboss/.../deploy{destination path on agent node}
-config file explaining:
---file1{source path} to be saved at /home/...../path1/{destination path on agent node}
---file2{source path} to be saved at /home/...../path2/{destination path on agent node}
...more files

Using puppet, I want to download file on agent-node (FIXED URL: http://mydomain/, unzip the file, read configuration file and move the file1/file2 etc to their destination path on agent node.
Differnet files would have different destination files locations

Any pointers how can this be done? Can I use puppet file resource and specify the destination path dynamically (based on values from the config file above?

Thanks in advance

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-04-23 13:03:25 -0600

JohnsonEarls gravatar image

updated 2015-04-23 13:05:04 -0600

The short answer is that what you're asking is very difficult.

The main problem you run into is that the resources in your puppet catalog cannot depend on content that is generated by other resources in the catalog. Your method of "download, extract, then install based off the extracted files" won't work, because the catalog has to be completely compiled before any of the resources take effect, and so the "install based off the extracted files" won't work.

What I was able to come up with follows. It's a release_installer module with 4 classes and 1 defined type. It's a bit complicated for an "example", but it follows the inheritance model that seems to be a "best practice" in puppet. For this module to work, you have to have the camptocamp-archive module installed from the Forge and be running at least Puppet version 3.4.

First, the main release_installer class, /etc/puppet/modules/release_installer/manifests/init.pp:

# == Class: release_installer
# This class downloads and extracts a zip file containing a release
# and, using information from an install configuration file within
# that zip file, copies release files to their appropriate destinations.
# == Parameters
# [*install_cfg*]
#   The name of the configuration file within the zip file which
#   describes what files are to be installed where.
#   Defaults to `install.cfg`.
# [*install_rxp*]
#   The regular expression that splits each line of the *install_cfg*
#   file into a (file,destination) pair.
#   Defaults to `[ \t]*=>[ \t]*`
#   This is install_cfg file with lines of the form `file => destination`.
# [*release_dest*]
#   The destination directory in which to extract the contents of the zip file.
#   This should be a stable directory; avoid `/tmp` or `/var/tmp` directories
#   where the contents might be erased, or the zip file will be re-extracted
#   and re-installed repeatedly.
#   Defaults to `/var/lib/release`.
# [*release_src*]
#   The URL of the release zip file.  This parameter is required.
class release_installer (
    $install_cfg  = $release_installer::params::install_cfg ,
    $install_rxp  = $release_installer::params::install_rxp ,
    $release_dest = $release_installer::params::release_dest ,
    $release_src  = $release_installer::params::release_src ,
) inherits release_installer::params {
    if !defined('$release_src') { fail("No release_src provided") }
    contain release_installer::download
    contain release_installer::install
    Class['release_installer::download'] ->

Next, the release_installer::params class, /etc/puppet/modules/release_installer/manifests/params.pp, defines the default values for the parameters:

# The params base class.  This defines the default values for the
# parameters, and provides a non-parameterized base class for the
# parameterized main class to inherit.
class release_installer::params {
    $install_cfg  = 'install.cfg'
    $install_rxp  = '[ \t]*=>[ \t]*'
    $release_dest = '/var/lib/release'
    $release_src  = undef

The release_installer::download class, /etc/puppet/modules/release_installer/manifests/download.pp, takes care of downloading and extracting the zip file for you, using the camptocamp-archive Forge module.

# The download class.  This downloads the zip file from the release
# source and extracts it into the release destination, using the
# `archive` class from the `camptocamp-archive` Forge module.
class release_installer::download
inherits release_installer {
    archive { release_zip_archive:
        ensure => present ,
        url => $release_src ,
        target => $release_dest ,
        checksum => false ,
        extension => 'zip' ,
        src_target => "/tmp" ,

The release_installer::install class, /etc/puppet/modules/release_installer/manifests/install.pp, fetches the install configuration file from ... (more)

edit flag offensive delete link more

answered 2015-04-22 11:36:15 -0600

maynero gravatar image

updated 2015-04-22 11:43:16 -0600

  1. Instead of downloading the zip, use puppet capability to put files on agents using the "file" resource

    file { "C:\\Downloads\ ":
        ensure => present,
        source => "puppet:///extra_files/",
  2. Can you right script to do the extraction file? Also why not just arrange the zip file contents according to folder destination and just plain extract it on the agent node.

Also, a quick search on puppet forge:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2015-04-22 11:22:52 -0600

Seen: 2,233 times

Last updated: Apr 23 '15