Skip to content

A puppet-lint plugin to check for calls to `lookup` in parameters.

License

Notifications You must be signed in to change notification settings

voxpupuli/puppet-lint-lookup_in_parameter-check

Repository files navigation

puppet-lint-lookup_in_parameter-check

License Test Release RubyGem Version RubyGem Downloads codecov

A puppet-lint plugin to check for calls to lookup in parameters.

Installation

Add this line to your application's Gemfile:

gem 'puppet-lint-lookup_in_parameter-check'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install puppet-lint-lookup_in_parameter-check

Rationale

Usage of lookup for fetching the default value of a parameter is a smell that prevent a strict usage of the roles and profiles pattern.

Consider a module which has a main class (acme) class that install the software and a defined type (acme::module) that extend the configuration:

---
acme::config_dir: '/etc/acme'
# manifests/init.pp
class acme (
  Stdlib::Absolutepath $config_dir,
) {
  file { $config_dir:
    ensure => directory,
  }

  file { "${config_dir}/modules":
    ensure => directory,
  }
}

# manifests/module.pp
define acme::module (
  String[1] $config,
  Stdlib::Absolutepath $config_dir = lookup('acme::config_dir'),
) {
  file { "${config_dir}/modules/${title}":
    ensure  => file,
    content => $config,
  }
}

When configuring this module with a custom config_dir, one has to explicitely set this parameter all the time:

class { 'acme':
  config_dir => '/opt/acme',
}

acme::module { 'foo':
  config     => $foo_config,
  config_dir => '/opt/acme', # If not set, `/etc/acme` from hiera would be used
}

A better way is to include the main class from the defined class and use the variable from the main class like so:

# manifests/module.pp
define acme::module (
  String[1] $config,
) {
  include acme

  file { "${acme::config_dir}/modules/${title}":
    ensure  => file,
    content => $config,
  }
}

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/voxpupuli/puppet-lint-lookup_in_parameter-check. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the puppet-lint-lookup_in_parameter-check project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

A puppet-lint plugin to check for calls to `lookup` in parameters.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •