voxpupuli/puppet-archive

Name: puppet-archive

Owner: Vox Pupuli

Description: Compressed archive file download and extraction with native types/providers for Windows and Unix

Created: 2014-09-05 00:56:20.0

Updated: 2017-12-19 23:37:22.0

Pushed: 2018-01-04 17:15:18.0

Homepage: https://forge.puppet.com/puppet/archive

Size: 643

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Puppet Archive

License Build Status Code Coverage Puppet Forge Puppet Forge - downloads Puppet Forge - endorsement Puppet Forge - scores Camptocamp compatible

Table of Contents
  1. Overview
  2. Module Description
  3. Setup
  4. Usage
  5. Example
  6. Puppet URL
  7. File permission
  8. Network files
  9. Extract customization
  10. S3 Bucket
  11. Migrating from puppet-staging
  12. Reference
  13. Development
Overview

This module manages download, deployment, and cleanup of archive files.

Module Description

This module uses types and providers to download and manage compress files, with optional lifecycle functionality such as checksum, extraction, and cleanup. The benefits over existing modules such as puppet-staging:

This module is compatible with camptocamp/archive. For this it provides compatibility shims.

Setup

The module requires 7zip for windows clients which is installed via include '::archive'. On posix systems, curl is the default provider. The default provider can be overwritten by configuring resource defaults in site.pp:

ive {
ovider => 'ruby',

Users of the module is responsbile for archive package dependencies for alternative providers and all extraction utilities such as tar, gunzip, bunzip:

::facts['osfamily'] != 'windows' {
ckage { 'wget':
ensure => present,


ckage { 'bunzip':
ensure => present,


chive {
provider => 'wget',
require  => Package['wget', 'bunzip'],


Usage

Archive module dependency is managed by the archive class. This is only required for windows platform. By default 7zip is installed via chocolatey, but can be adjusted to use the msi package instead:

s { 'archive':
ven_zip_name     => '7-Zip 9.20 (x64 edition)',
ven_zip_source   => 'C:/Windows/Temp/7z920-x64.msi',
ven_zip_provider => 'windows',

Usage Example
ude '::archive' # NOTE: optional for posix platforms

ive { '/tmp/jta-1.1.jar':
sure        => present,
tract       => true,
tract_path  => '/tmp',
urce        => 'http://central.maven.org/maven2/javax/transaction/jta/1.1/jta-1.1.jar',
ecksum      => '2ca09f0b36ca7d71b762e14ea2ff09d5eac57558',
ecksum_type => 'sha1',
eates       => '/tmp/javax',
eanup       => true,


ive { '/tmp/test100k.db':
urce   => 'ftp://ftp.otenet.gr/test100k.db',
ername => 'speedtest',
ssword => 'speedtest',

Puppet URL

Since march 2017, the Archive type also supports puppet URLs. Here is an example of how to use this:

ive { '/home/myuser/help':
urce        => 'puppet:///modules/profile/help.tar.gz',
tract       => true,
tract_path  => $homedir,
eates       => "${homedir}/help" #directory inside tgz

File permission

When extracting files as non-root user, either ensure the target directory exists with the appropriate permission (see tomcat.pp for full working example):

name = 'apache-tomcat-9.0.0.M3'
ename = "${dirname}.zip"
tall_path = "/opt/${dirname}"

 { $install_path:
sure => directory,
ner  => 'tomcat',
oup  => 'tomcat',
de   => '0755',


ive { $filename:
th          => "/tmp/${filename}",
urce        => 'http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.0.M3/bin/apache-tomcat-9.0.0.M3.zip',
ecksum      => 'f2aaf16f5e421b97513c502c03c117fab6569076',
ecksum_type => 'sha1',
tract       => true,
tract_path  => '/opt',
eates       => "${install_path}/bin",
eanup       => true,
er          => 'tomcat',
oup         => 'tomcat',
quire       => File[$install_path],

or use an subscribing exec to chmod the directory afterwards:

name = 'apache-tomcat-9.0.0.M3'
ename = "${dirname}.zip"
tall_path = "/opt/${dirname}"

 { '/opt/tomcat':
sure => 'link',
rget => $install_path


ive { $filename:
th          => "/tmp/${filename}",
urce        => "http://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.0.M3/bin/apache-tomcat-9.0.0.M3.zip",
ecksum      => 'f2aaf16f5e421b97513c502c03c117fab6569076',
ecksum_type => 'sha1',
tract       => true,
tract_path  => '/opt',
eates       => $install_path,
eanup       => 'true',
quire       => File[$install_path],


 { 'tomcat permission':
mmand   => "chown tomcat:tomcat $install_path",
th      => $::path,
bscribe => Archive[$filename],

Network files

For large binary files that needs to be extracted locally, instead of copying the file from the network fileshare, simply set the file path to be the same as the source and archive will use the network file location:

ive { '/nfs/repo/software.zip':
urce        => '/nfs/repo/software.zip'
tract       => true,
tract_path  => '/opt',
ecksum_type => 'none', # typically unecessary
eanup       => false,  # keep the file on the server

Extract Customization

The extract_flags or extract_command parameters can be used to override the default extraction command/flag (defaults are specified in achive.rb).

r striping directories:
ive { '/var/lib/kafka/kafka_2.10-0.8.2.1.tgz':
sure          => present,
tract         => true,
tract_command => 'tar xfz %s --strip-components=1',
tract_path    => '/opt/kafka_2.10-0.8.2.1',
eanup         => true,
eates         => '/opt/kafka_2.10-0.8.2.1/config',


p freshen existing files (zip -of %s instead of zip -o %s):
ive { '/var/lib/example.zip':
tract       => true,
tract_path  => '/opt',
tract_flags => '-of',
eanup       => true,
bscribe     => ...,

S3 bucket

S3 support is implemented via the AWS CLI. By default this dependency is only installed for Linux VMs running on AWS, or enabled via aws_cli_install option:

s { '::archive':
s_cli_install => true,


e AWS cli guide for credential and configuration settings:
tp://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
 { '/root/.aws/credentials':
sure => file,
.

 { '/root/.aws/config':
sure => file,
.


ive { '/tmp/gravatar.png':
sure => present,
urce => 's3://bodecoio/gravatar.png',

NOTE: Alternative s3 provider support can be implemented by overriding the s3_download method:

Download customizations

In some cases you may need custom flags for curl/wget/s3 which can be supplied via download_options. Since this parameter is provider specific, beware of the order of defaults:

This option can also be applied globally to address issues for specific OS:

::facts['osfamily'] != 'RedHat' {
chive {
download_options => '--tlsv1',


Migrating from puppet-staging

It is recommended to use puppet-archive instead of puppet-staging. Users wishing to migrate may find the following examples useful.

Simple example without extraction puppet-staging
s { 'staging':
th  => '/tmp/staging',


ing::file { 'master.zip':
urce => 'https://github.com/voxpupuli/puppet-archive/archive/master.zip',

puppet-archive
ive { '/tmp/staging/master.zip':
urce => 'https://github.com/voxpupuli/puppet-archive/archive/master.zip',

Example with zip file extraction puppet-staging
s { 'staging':
th  => '/tmp/staging',


ing::file { 'master.zip':
urce  => 'https://github.com/voxpupuli/puppet-archive/archive/master.zip',

ing::extract { 'master.zip':
rget  => '/tmp/staging/master.zip',
eates => '/tmp/staging/puppet-archive-master',

puppet-archive
ive { '/tmp/staging/master.zip':
urce       => 'https://github.com/voxpupuli/puppet-archive/archive/master.zip',
tract      => true,
tract_path => '/tmp/staging',
eates      => '/tmp/staging/puppet-archive-master',
eanup      => false,

Reference
Classes
Define Resources
Resources
Archive Archive::Artifactory Archive::Artifactory Example
name = 'gradle-1.0-milestone-4-20110723151213+0300'
ename = "${dirname}-bin.zip"

ive::artifactory { $filename:
chive_path => '/tmp',
l          => "http://repo.jfrog.org/artifactory/distributions/org/gradle/${filename}",
tract      => true,
tract_path => '/opt',
eates      => "/opt/${dirname}",
eanup      => true,


 { '/opt/gradle':
sure => link,
rget => "/opt/${dirname}",

Archive::Nexus Archive::Nexus Example
ive::nexus { '/tmp/jtstand-ui-0.98.jar':
l        => 'https://oss.sonatype.org',
v        => 'org.codehaus.jtstand:jtstand-ui:0.98',
pository => 'codehaus-releases',
ckaging  => 'jar',
tract    => false,

Development

We highly welcome new contributions to this module, especially those that include documentation, and rspec tests ;) but will happily guide you through the process, so, yes, please submit that pull request!

Note: If you are writing a dependent module that include specs in it, you will need to set the puppetversion fact in your puppet-rspec tests. You can do that by adding it to the default facts of your spec/spec_helper.rb:

c.configure do |c|
default_facts = { :puppetversion => Puppet.version }


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.