diff --git a/.fixtures.yml b/.fixtures.yml index dc6b41f..67added 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,7 +1,7 @@ fixtures: repositories: 'stdlib': repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' - ref: '4.0.0' + ref: '4.2.0' symlinks: 'concat': '#{source_dir}' diff --git a/.gitignore b/.gitignore index 143345e..d681eca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .pkg Gemfile.lock vendor spec/fixtures .rspec_system .bundle *.sw* +.vagrant diff --git a/.travis.yml b/.travis.yml index 4e72cd4..1288819 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,40 +1,40 @@ --- branches: only: - master language: ruby bundler_args: --without development script: bundle exec rake spec SPEC_OPTS='--format documentation' # work around RubyGems 2.2.0 breaking ruby 1.8.7 # https://github.com/rubygems/rubygems/pull/763 # https://github.com/freerange/mocha/commit/66bab2a8f4e7cd8734bf88e6f32157c0d5153125 before_install: - gem update --system 2.1.11 - gem --version rvm: - 1.8.7 - 1.9.3 - 2.0.0 env: matrix: - - PUPPET_GEM_VERSION="2.7.3" FACTER_GEM_VERSION="1.6.0" + - PUPPET_GEM_VERSION="2.7.6" FACTER_GEM_VERSION="1.6.0" - PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - PUPPET_GEM_VERSION="~> 3.0" matrix: fast_finish: true exclude: - rvm: 1.9.3 - env: PUPPET_GEM_VERSION="2.7.3" FACTER_GEM_VERSION="1.6.0" + env: PUPPET_GEM_VERSION="2.7.6" FACTER_GEM_VERSION="1.6.0" - rvm: 1.9.3 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - rvm: 1.9.3 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" - rvm: 2.0.0 - env: PUPPET_GEM_VERSION="2.7.3" FACTER_GEM_VERSION="1.6.0" + env: PUPPET_GEM_VERSION="2.7.6" FACTER_GEM_VERSION="1.6.0" - rvm: 2.0.0 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0" - rvm: 2.0.0 env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0" notifications: email: false diff --git a/Modulefile b/Modulefile index ea9ef2c..bc1f199 100644 --- a/Modulefile +++ b/Modulefile @@ -1,9 +1,9 @@ name 'puppetlabs-concat' version '1.1.0' source 'git://github.com/puppetlabs/puppetlabs-concat.git' author 'Puppetlabs' license 'Apache 2.0' summary 'Concat module' description 'Concat module' project_page 'http://github.com/puppetlabs/puppetlabs-concat' -dependency 'puppetlabs/stdlib', '>= 4.0.0' +dependency 'puppetlabs/stdlib', '>= 4.2.0' diff --git a/README.md b/README.md index 60eca38..3f26ee7 100644 --- a/README.md +++ b/README.md @@ -1,441 +1,443 @@ #Concat [](https://travis-ci.org/puppetlabs/puppetlabs-concat) ####Table of Contents 1. [Overview](#overview) 2. [Module Description - What the module does and why it is useful](#module-description) 3. [Setup - The basics of getting started with concat](#setup) * [What concat affects](#what-concat-affects) * [Setup requirements](#setup-requirements) * [Beginning with concat](#beginning-with-concat) 4. [Usage - Configuration options and additional functionality](#usage) * [API _deprecations_](#api-deprecations) 5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) 5. [Limitations - OS compatibility, etc.](#limitations) 6. [Development - Guide for contributing to the module](#development) ##Overview This module constructs files from multiple fragments in an ordered way. ##Module Description This module lets you use many concat::fragment{} resources throughout your modules to construct a single file at the end. It does this through a shell (or ruby) script and a temporary holding space for the fragments. ##Setup ###What concat affects * Installs concatfragments.[sh|rb] based on platform. * Adds a concat/ directory into Puppets `vardir`. ###Beginning with concat To start using concat you need to create: * A concat{} resource for the final file. * One or more concat::fragment{}'s. A minimal example might be: ```puppet concat { '/tmp/file': ensure => present, } concat::fragment { 'tmpfile': target => '/tmp/file' content => 'test contents', order => '01' } ``` ##Usage Please be aware that there have been a number of [API _deprecations_](#api-deprecations). If you wanted a /etc/motd file that listed all the major modules on the machine. And that would be maintained automatically even if you just remove the include lines for other modules you could use code like below, a sample /etc/motd would be:
Puppet modules on this server: -- Apache -- MySQLLocal sysadmins can also append to the file by just editing /etc/motd.local their changes will be incorporated into the puppet managed motd. ```puppet class motd { $motd = '/etc/motd' concat { $motd: owner => 'root', group => 'root', mode => '0644' } concat::fragment{ 'motd_header': target => $motd, content => "\nPuppet modules on this server:\n\n", order => '01' } # local users on the machine can append to motd by just creating # /etc/motd.local concat::fragment{ 'motd_local': target => $motd, source => '/etc/motd.local', order => '15' } } # used by other modules to register themselves in the motd -define motd::register($content="", $order=10) { +define motd::register($content="", $order='10') { if $content == "" { $body = $name } else { $body = $content } concat::fragment{ "motd_fragment_$name": target => '/etc/motd', order => $order, content => " -- $body\n" } } ``` To use this you'd then do something like: ```puppet class apache { include apache::install, apache::config, apache::service motd::register{ 'Apache': } } ``` ##Reference ###Classes ####Public classes ####Private classes * `concat::setup`: Sets up the concat script/directories. ###Parameters ###Defines ####concat #####`ensure` Controls if the combined file is present or absent. ######Example - ensure => present - ensure => absent #####`path` Controls the destination of the file to create. ######Example - path => '/tmp/filename' #####`owner` Set the owner of the combined file. ######Example - owner => 'root' #####`group` Set the group of the combined file. ######Example - group => 'root' #####`mode` Set the mode of the combined file. ######Example - mode => '0644' #####`warn` Determine if a warning message should be added at the top of the file to let users know it was autogenerated by Puppet. ######Example - warn => true - warn => false #####`warn_message` Set the contents of the warning message. ######Example - warn_message => 'This file is autogenerated!' #####`force` Determine if empty files are allowed when no fragments were added. ######Example - force => true - force => false #####`backup` Controls the filebucket behavior used for the file. ######Example - backup => 'puppet' #####`replace` Controls if Puppet should replace the destination file if it already exists. ######Example - replace => true - replace => false #####`order` Controls the way in which the shell script chooses to sort the files. It's rare you'll need to adjust this. ######Allowed Values - order => 'alpha' - order => 'numeric' #####`ensure_newline` Ensure there's a newline at the end of the fragments. ######Example - ensure_newline => true - ensure_newline => false ####concat::fragment #####`target` Choose the destination file of the fragment. ######Example - target => '/tmp/testfile' #####`content` Create the content of the fragment. ######Example - content => 'test file contents' #####`source` Find the sources within Puppet of the fragment. ######Example - source => 'puppet:///modules/test/testfile' - source => ['puppet:///modules/test/1', 'puppet:///modules/test/2'] #####`order` Order the fragments. ######Example - order => '01' +Best practice is to pass a string to this parameter but integer values are accepted. + #####`ensure` Control the file of fragment created. ######Example - ensure => 'present' - ensure => 'absent' - ensure => 'file' - ensure => 'directory' #####`mode` Set the mode of the fragment. ######Example - mode => '0644' #####`owner` Set the owner of the fragment. ######Example - owner => 'root' #####`group` Set the group of the fragment. ######Example - group => 'root' #####`backup` Control the filebucket behavior for the fragment. ######Example - backup => 'puppet' ### API _deprecations_ #### Since version `1.0.0` ##### `concat{}` `warn` parameter ```puppet concat { '/tmp/file': ensure => present, warn => 'true', # generates stringified boolean value warning } ``` Using stringified Boolean values as the `warn` parameter to `concat` is deprecated, generates a catalog compile time warning, and will be silently treated as the concatenated file header/warning message in a future release. The following strings are considered a stringified Boolean value: * `'true'` * `'yes'` * `'on'` * `'false'` * `'no'` * `'off'` Please migrate to using the Puppet DSL's native [Boolean data type](http://docs.puppetlabs.com/puppet/3/reference/lang_datatypes.html#booleans). ##### `concat{}` `gnu` parameter ```puppet concat { '/tmp/file': ensure => present, gnu => $foo, # generates deprecation warning } ``` The `gnu` parameter to `concat` is deprecated, generates a catalog compile time warning, and has no effect. This parameter will be removed in a future release. Note that this parameter was silently ignored in the `1.0.0` release. ##### `concat::fragment{}` `ensure` parameter ```puppet concat::fragment { 'cpuinfo': ensure => '/proc/cpuinfo', # generates deprecation warning target => '/tmp/file', } ``` Passing a value other than `'present'` or `'absent'` as the `ensure` parameter to `concat::fragment` is deprecated and generates a catalog compile time warning. The warning will become a catalog compilation failure in a future release. This type emulates the Puppet core `file` type's disfavored [`ensure` semantics](http://docs.puppetlabs.com/references/latest/type.html#file-attribute-ensure) of treating a file path as a directive to create a symlink. This feature is problematic in several ways. It copies an API semantic of another type that is both frowned upon and not generally well known. It's behavior may be surprising in that the target concatenated file will not be a symlink nor is there any common file system that has a concept of a section of a plain file being symbolically linked to another file. Additionally, the behavior is generally inconsistent with most Puppet types in that a missing source file will be silently ignored. If you want to use the content of a file as a fragment please use the `source` parameter. ##### `concat::fragment{}` `mode/owner/group` parameters ```puppet concat::fragment { 'foo': target => '/tmp/file', content => 'foo', mode => $mode, # generates deprecation warning owner => $owner, # generates deprecation warning group => $group, # generates deprecation warning } ``` The `mode` parameter to `concat::fragment` is deprecated, generates a catalog compile time warning, and has no effect. The `owner` parameter to `concat::fragment` is deprecated, generates a catalog compile time warning, and has no effect. The `group` parameter to `concat::fragment` is deprecated, generates a catalog compile time warning, and has no effect. These parameters had no user visible effect in version `1.0.0` and will be removed in a future release. ##### `concat::fragment{}` `backup` parameter ```puppet concat::fragment { 'foo': target => '/tmp/file', content => 'foo', backup => 'bar', # generates deprecation warning } ``` The `backup` parameter to `concat::fragment` is deprecated, generates a catalog compile time warning, and has no effect. It will be removed in a future release. In the `1.0.0` release this parameter controlled file bucketing of the file fragment. Bucketting the fragment(s) is redundant with bucketting the final concatenated file and this feature has been removed. ##### `class { 'concat::setup': }` ```puppet include concat::setup # generates deprecation warning class { 'concat::setup: } # generates deprecation warning ``` The `concat::setup` class is deprecated as a public API of this module and should no longer be directly included in the manifest. This class may be removed in a future release. ##### Parameter validation While not an API depreciation, users should be aware that all public parameters in this module are now validated for at least variable type. This may cause validation errors in a manifest that was previously silently misbehaving. ##Limitations This module has been tested on: * RedHat Enterprise Linux (and Centos) 5/6 * Debian 6/7 * Ubuntu 12.04 Testing on other platforms has been light and cannot be guaranteed. #Development Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) ###Contributors The list of contributors can be found at: https://github.com/puppetlabs/puppetlabs-concat/graphs/contributors diff --git a/manifests/fragment.pp b/manifests/fragment.pp index a51b8c2..daa6a23 100644 --- a/manifests/fragment.pp +++ b/manifests/fragment.pp @@ -1,121 +1,123 @@ # == Define: concat::fragment # # Puts a file fragment into a directory previous setup using concat # # === Options: # # [*target*] # The file that these fragments belong to # [*content*] # If present puts the content into the file # [*source*] # If content was not specified, use the source # [*order*] # By default all files gets a 10_ prefix in the directory you can set it to # anything else using this to influence the order of the content in the file # [*ensure*] # Present/Absent or destination to a file to include another file # [*mode*] # Deprecated # [*owner*] # Deprecated # [*group*] # Deprecated # [*backup*] # Deprecated # define concat::fragment( $target, $content = undef, $source = undef, $order = '10', $ensure = undef, $mode = undef, $owner = undef, $group = undef, $backup = undef ) { validate_string($target) validate_string($content) if !(is_string($source) or is_array($source)) { fail('$source is not a string or an Array.') } - validate_string($order) + if !(is_string($order) or is_integer($order)) { + fail('$order is not a string or integer.') + } if $mode { warning('The $mode parameter to concat::fragment is deprecated and has no effect') } if $owner { warning('The $owner parameter to concat::fragment is deprecated and has no effect') } if $group { warning('The $group parameter to concat::fragment is deprecated and has no effect') } if $backup { warning('The $backup parameter to concat::fragment is deprecated and has no effect') } if $ensure == undef { $_ensure = getparam(Concat[$target], 'ensure') } else { if ! ($ensure in [ 'present', 'absent' ]) { warning('Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.') } $_ensure = $ensure } include concat::setup $safe_name = regsubst($name, '[/:\n]', '_', 'GM') $safe_target_name = regsubst($target, '[/:\n]', '_', 'GM') $concatdir = $concat::setup::concatdir $fragdir = "${concatdir}/${safe_target_name}" $fragowner = $concat::setup::fragment_owner $fragmode = $concat::setup::fragment_mode # The file type's semantics are problematic in that ensure => present will # not over write a pre-existing symlink. We are attempting to provide # backwards compatiblity with previous concat::fragment versions that # supported the file type's ensure => /target syntax # be paranoid and only allow the fragment's file resource's ensure param to # be file, absent, or a file target $safe_ensure = $_ensure ? { '' => 'file', undef => 'file', 'file' => 'file', 'present' => 'file', 'absent' => 'absent', default => $_ensure, } # if it looks line ensure => /target syntax was used, fish that out if ! ($_ensure in ['', 'present', 'absent', 'file' ]) { $ensure_target = $_ensure } else { $ensure_target = undef } # the file type's semantics only allows one of: ensure => /target, content, # or source if ($ensure_target and $source) or ($ensure_target and $content) or ($source and $content) { fail('You cannot specify more than one of $content, $source, $ensure => /target') } if ! ($content or $source or $ensure_target) { crit('No content, source or symlink specified') } # punt on group ownership until some point in the distant future when $::gid # can be relied on to be present file { "${fragdir}/fragments/${order}_${safe_name}": ensure => $safe_ensure, owner => $fragowner, mode => $fragmode, source => $source, content => $content, backup => false, alias => "concat_fragment_${name}", notify => Exec["concat_${target}"] } } diff --git a/spec/unit/defines/concat_fragment_spec.rb b/spec/unit/defines/concat_fragment_spec.rb index 3b5269e..3c61aab 100644 --- a/spec/unit/defines/concat_fragment_spec.rb +++ b/spec/unit/defines/concat_fragment_spec.rb @@ -1,267 +1,267 @@ require 'spec_helper' describe 'concat::fragment', :type => :define do shared_examples 'fragment' do |title, params| params = {} if params.nil? p = { :content => nil, :source => nil, :order => 10, :ensure => 'present', }.merge(params) safe_name = title.gsub(/[\/\n]/, '_') safe_target_name = p[:target].gsub(/[\/\n]/, '_') concatdir = '/var/lib/puppet/concat' fragdir = "#{concatdir}/#{safe_target_name}" id = 'root' if p[:ensure] == 'absent' safe_ensure = p[:ensure] else safe_ensure = 'file' end let(:title) { title } let(:facts) {{ :concat_basedir => concatdir, :id => id }} let(:params) { params } let(:pre_condition) do "concat{ '#{p[:target]}': }" end it do should contain_class('concat::setup') should contain_concat(p[:target]) should contain_file("#{fragdir}/fragments/#{p[:order]}_#{safe_name}").with({ :ensure => safe_ensure, :owner => id, :mode => '0640', :source => p[:source], :content => p[:content], :alias => "concat_fragment_#{title}", :backup => false, }) end end context 'title' do ['0', '1', 'a', 'z'].each do |title| it_behaves_like 'fragment', title, { :target => '/etc/motd', } end end # title context 'target =>' do ['./etc/motd', 'etc/motd', 'motd_header'].each do |target| context target do it_behaves_like 'fragment', target, { :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) {{ :target => false }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # target => context 'ensure =>' do ['present', 'absent'].each do |ens| context ens do it_behaves_like 'fragment', 'motd_header', { :ensure => ens, :target => '/etc/motd', } end end context 'any value other than \'present\' or \'absent\'' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) {{ :ensure => 'invalid', :target => '/etc/motd' }} it 'should create a warning' do pending('rspec-puppet support for testing warning()') end end end # ensure => context 'content =>' do ['', 'ashp is our hero'].each do |content| context content do it_behaves_like 'fragment', 'motd_header', { :content => content, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) {{ :content => false, :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string/) end end end # content => context 'source =>' do ['', '/foo/bar', ['/foo/bar', '/foo/baz']].each do |source| context source do it_behaves_like 'fragment', 'motd_header', { :source => source, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) {{ :source => false, :target => '/etc/motd' }} it 'should fail' do expect { should }.to raise_error(Puppet::Error, /is not a string or an Array/) end end end # source => context 'order =>' do ['', '42', 'a', 'z'].each do |order| context '\'\'' do it_behaves_like 'fragment', 'motd_header', { :order => order, :target => '/etc/motd', } end end context 'false' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) {{ :order => false, :target => '/etc/motd' }} it 'should fail' do - expect { should }.to raise_error(Puppet::Error, /is not a string/) + expect { should }.to raise_error(Puppet::Error, /is not a string or integer/) end end end # order => context 'more than one content source' do error_msg = 'You cannot specify more than one of $content, $source, $ensure => /target' context 'ensure => target and source' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) do { :target => '/etc/motd', :ensure => '/foo', :source => '/bar', } end it 'should fail' do expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'ensure => target and content' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) do { :target => '/etc/motd', :ensure => '/foo', :content => 'bar', } end it 'should fail' do expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end context 'source and content' do let(:title) { 'motd_header' } let(:facts) {{ :concat_basedir => '/tmp' }} let(:params) do { :target => '/etc/motd', :source => '/foo', :content => 'bar', } end it 'should fail' do expect { should }.to raise_error(Puppet::Error, /#{Regexp.escape(error_msg)}/m) end end end # more than one content source describe 'deprecated parameter' do context 'mode =>' do context '1755' do it_behaves_like 'fragment', 'motd_header', { :mode => '1755', :target => '/etc/motd', } it 'should create a warning' do pending('rspec-puppet support for testing warning()') end end end # mode => context 'owner =>' do context 'apenny' do it_behaves_like 'fragment', 'motd_header', { :owner => 'apenny', :target => '/etc/motd', } it 'should create a warning' do pending('rspec-puppet support for testing warning()') end end end # owner => context 'group =>' do context 'apenny' do it_behaves_like 'fragment', 'motd_header', { :group => 'apenny', :target => '/etc/motd', } it 'should create a warning' do pending('rspec-puppet support for testing warning()') end end end # group => context 'backup =>' do context 'foo' do it_behaves_like 'fragment', 'motd_header', { :backup => 'foo', :target => '/etc/motd', } it 'should create a warning' do pending('rspec-puppet support for testing warning()') end end end # backup => end # deprecated params end