大网数据广告活动
服务器运维问答

Why does puppet module generate produce a Gemfile, and what is its purpose?

· 52CE 我爱测

I recently ran puppet module generate , and ended up with a whole lot of crap that looked unnecessary for a simple module. I mean, a lot of minimal modules amount to templating a configuration file or two and letting an open sour…

问题原文

原帖链接 · Nathan Basanese · CC BY-SA 3.0

I recently ran puppet module generate, and ended up with a whole lot of crap that looked unnecessary for a simple module. I mean, a lot of minimal modules amount to templating a configuration file or two and letting an open source Puppet module do the heavy lifting.

Puppet's documentation explained most of puppet module generate here:

https://docs.puppet.com/puppet/4.9/modules_fundamentals.html

However, I didn't see anything in there about the Gemfile.

Of what use is the Gemfile generated by puppet module generate?

$ puppet module generate nathan-myapp_consul
$ cd myapp_consul/
$ ls
Gemfile     README.md   Rakefile    examples    manifests   metadata.json   spec

Here are the contents of this file:

source ENV['GEM_SOURCE'] || 'https://rubygems.org'

puppetversion = ENV.key?('PUPPET_VERSION') ? ENV['PUPPET_VERSION'] : ['>= 3.3']
gem 'metadata-json-lint'
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 1.0.0'
gem 'puppet-lint', '>= 1.0.0'
gem 'facter', '>= 1.7.0'
gem 'rspec-puppet'

# rspec must be v2 for ruby 1.8.7
if RUBY_VERSION >= '1.8.7' && RUBY_VERSION < '1.9'
  gem 'rspec', '~> 2.0'
  gem 'rake', '~> 10.0'
else
  # rubocop requires ruby >= 1.9
  gem 'rubocop'
end

Gemfile produced by puppet module generate, what is the point of you?

已采纳解答

原帖链接 · Dominic Cleal · CC BY-SA 3.0

A Gemfile is used by Ruby's Bundler app to install RubyGems (Ruby libraries) used by the project - in this case, gems that can be used to develop the module. It's not used when installing or using the module within Puppet.

If you have Ruby installed, you can install these gems by running:

gem install bundler
bundle install  # or add `--path vendor` to install within the directory

A quick run-down of the purpose of these gems, and why you might find them useful:

  • metadata-json-lint verifies the metadata.json file is correct, otherwise Puppet may not load the module and you couldn't upload it to the Forge
  • puppetlabs_spec_helper is a helper for running tests etc.
  • puppet-lint validates your Puppet manifests against the Puppet style guide (more info)
  • rspec-puppet, rspec let you write tests for Puppet classes, defined types etc to check that they compile without errors and create the right resources with the correct parameters (more info)
  • rake is used to run preconfigured tasks from Rakefile, i.e. rake test will run all of the above and also validates manifests, ERB files etc.
  • rubocop validates your Ruby code against a Ruby style guide, the equivalent to puppet-lint

As you suggest, these aren't necessary for a minimal module, but they are useful. You don't need to write tests or even lint your code, but using the tools may help you create a more reliable module and help you make changes without the risk of it not working within Puppet.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。